v1.27.0-a #10
@ -92,11 +92,13 @@ func (d *debug) chainStateSSE(w http.ResponseWriter, r *http.Request) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(rpcInfos))
|
||||
for addr, token := range apiInfos {
|
||||
addr := addr
|
||||
ai := cliutil.APIInfo{
|
||||
Addr: addr,
|
||||
Token: token,
|
||||
}
|
||||
|
||||
go func(info string) {
|
||||
defer wg.Done()
|
||||
var clayers []string
|
||||
for layer, a := range confNameToAddr {
|
||||
if a == addr {
|
||||
@ -104,20 +106,20 @@ func (d *debug) chainStateSSE(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
da, err := ai.DialArgs("v1")
|
||||
if err != nil {
|
||||
log.Warnw("DialArgs", "error", err)
|
||||
|
||||
infosLk.Lock()
|
||||
infos[addr] = rpcInfo{
|
||||
myinfo := rpcInfo{
|
||||
Address: ai.Addr,
|
||||
Reachable: false,
|
||||
CLayers: clayers,
|
||||
}
|
||||
defer func() {
|
||||
infosLk.Lock()
|
||||
infos[ai.Addr] = myinfo
|
||||
infosLk.Unlock()
|
||||
|
||||
wg.Done()
|
||||
continue
|
||||
}()
|
||||
da, err := ai.DialArgs("v1")
|
||||
if err != nil {
|
||||
log.Warnw("DialArgs", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
ah := ai.AuthHeader()
|
||||
@ -125,21 +127,8 @@ func (d *debug) chainStateSSE(w http.ResponseWriter, r *http.Request) {
|
||||
v1api, closer, err := client.NewFullNodeRPCV1(ctx, da, ah)
|
||||
if err != nil {
|
||||
log.Warnf("Not able to establish connection to node with addr: %s", addr)
|
||||
|
||||
infosLk.Lock()
|
||||
infos[addr] = rpcInfo{
|
||||
Address: ai.Addr,
|
||||
Reachable: false,
|
||||
CLayers: clayers,
|
||||
return
|
||||
}
|
||||
infosLk.Unlock()
|
||||
|
||||
wg.Done()
|
||||
continue
|
||||
}
|
||||
|
||||
go func(info string) {
|
||||
defer wg.Done()
|
||||
defer closer()
|
||||
|
||||
ver, err := v1api.Version(ctx)
|
||||
@ -164,26 +153,21 @@ func (d *debug) chainStateSSE(w http.ResponseWriter, r *http.Request) {
|
||||
syncState = fmt.Sprintf("behind (%s behind)", time.Since(time.Unix(int64(head.MinTimestamp()), 0)).Truncate(time.Second))
|
||||
}
|
||||
|
||||
var out rpcInfo
|
||||
out.Address = ai.Addr
|
||||
out.CLayers = clayers
|
||||
out.Reachable = true
|
||||
out.Version = ver.Version
|
||||
out.SyncState = syncState
|
||||
|
||||
infosLk.Lock()
|
||||
infos[info] = out
|
||||
infosLk.Unlock()
|
||||
|
||||
myinfo = rpcInfo{
|
||||
Address: ai.Addr,
|
||||
CLayers: clayers,
|
||||
Reachable: true,
|
||||
Version: ver.Version,
|
||||
SyncState: syncState,
|
||||
}
|
||||
}(addr)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
infoList := make([]rpcInfo, 0, len(infos))
|
||||
for _, info := range infos {
|
||||
infoList = append(infoList, info)
|
||||
var infoList []rpcInfo
|
||||
for _, i := range infos {
|
||||
infoList = append(infoList, i)
|
||||
}
|
||||
|
||||
sort.Slice(infoList, func(i, j int) bool {
|
||||
return infoList[i].Address < infoList[j].Address
|
||||
})
|
||||
@ -200,6 +184,12 @@ func (d *debug) chainStateSSE(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
time.Sleep(time.Duration(build.BlockDelaySecs) * time.Second)
|
||||
|
||||
select { // stop running if there is reader.
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user