Skip to content

Commit e796679

Browse files
committed
wasm-client: close client conn in a goroutine
Close the client connection in a goroutine. This fixes a bug that was introduced with the upgrade to grpc v0.18.1. The caused the websocket to freeze during closure when the client disconnected, and therefore the entire wasm-client would freeze. When closing the connection in a goroutine, the websocket is closed correctly.
1 parent d8c9f92 commit e796679

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cmd/wasm-client/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,14 @@ func (w *wasmClient) IsConnected(_ js.Value, _ []js.Value) interface{} {
290290

291291
func (w *wasmClient) Disconnect(_ js.Value, _ []js.Value) interface{} {
292292
if w.lndConn != nil {
293-
if err := w.lndConn.Close(); err != nil {
294-
log.Errorf("Error closing RPC connection: %v", err)
295-
}
296-
w.lndConn = nil
293+
// We launch the closure of the connection in a goroutine to avoid
294+
// that the JS websocket freezes and blocks while closing.
295+
go func() {
296+
if err := w.lndConn.Close(); err != nil {
297+
log.Errorf("Error closing RPC connection: %v", err)
298+
}
299+
w.lndConn = nil
300+
}()
297301
}
298302

299303
return nil

0 commit comments

Comments
 (0)