grid: Simpler reconnect logic (#18889)

Do not rely on `connChange` to do reconnects.

Instead, you can block while the connection is running and reconnect 
when handleMessages returns.

Add fully async monitoring instead of monitoring on the main goroutine 
and keep this to avoid full network lockup.
This commit is contained in:
Klaus Post
2024-01-28 08:46:15 -08:00
committed by GitHub
parent 6347fb6636
commit 38de8e6936
4 changed files with 50 additions and 34 deletions

View File

@@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"runtime/debug"
"sync"
"sync/atomic"
"time"
@@ -138,7 +139,8 @@ func newMuxStream(ctx context.Context, msg message, c *Connection, handler Strea
}
if r := recover(); r != nil {
logger.LogIf(ctx, fmt.Errorf("grid handler (%v) panic: %v", msg.Handler, r))
err := RemoteErr(fmt.Sprintf("panic: %v", r))
debug.PrintStack()
err := RemoteErr(fmt.Sprintf("remote call panic: %v", r))
handlerErr = &err
}
if debugPrint {
@@ -244,8 +246,10 @@ func (m *muxServer) message(msg message) {
if len(msg.Payload) > 0 {
logger.LogIf(m.ctx, fmt.Errorf("muxServer: EOF message with payload"))
}
close(m.inbound)
m.inbound = nil
if m.inbound != nil {
close(m.inbound)
m.inbound = nil
}
return
}