Closed mynlexi closed 1 week ago
if I manually close the golang connection
err = wsutil.WriteClientMessage(conn, ws.OpClose, []byte(""))
the issues seems to go away, but strange nonetheless
Hi, @mynlexi I'm having some problems trying to emulate this problem, this is still happening in v0.5.7 on Mac?
Go code:
package main
import (
"context"
"github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil"
)
func main() {
conn, _, _, _ := ws.DefaultDialer.Dial(context.Background(), "ws://localhost:8080")
msg := []byte("Hello")
_ = wsutil.WriteClientMessage(conn, ws.OpText, msg)
_ = conn.Close()
}
Bun code:
Bun.serve({
port:8080,
fetch(req, server) {
server.upgrade(req);
},
websocket: {
open: ws => {
console.log("ready to receive data ws \n");
ws.send("ready");
},
close: ws => {
console.log("\n want to close");
console.log("closed download ws");
},
message(ws, message) {
ws.send(message); // echo back the message
},
},
});
Output:
ready to receive data ws
want to close
closed download was
PS: I'm on an Linux x86 machine so maybe this is an Mac M1 related problem
Yeah seems like it:
% bun main.ts
[0.04ms] ".env"
Listening on 0.0.0.0:3005
status sync 201
ready to receive data ws
.................................................
closed download ws
set DB for WorkspaceID 1
^C
lorenz in ~/code/src/github.com/mynlexi/voiceline/voiceline_spotlight on main
% bun main.ts
[0.03ms] ".env"
Listening on 0.0.0.0:3005
status sync 201
ready to receive data ws
.................................................set DB for WorkspaceID 1
^C
lorenz in ~/code/src/github.com/mynlexi/voiceline/voiceline_spotlight on main
% bun upgrade
Congrats! You're already on the latest version of bun (which is v0.5.7)
We have test coverage for this
If you still don't receive a close event please let us know and ideally include a reproduction
What version of Bun is running?
0.5.6
What platform is your computer?
Darwin 22.1.0 arm64 arm
What steps can reproduce the bug?
Using bao.js (but straight import for ServerWebsocket from bun)
We send json from Golang server to bun server Golang:
Bun:
What is the expected behavior?
What do you see instead?
close never fires
but on golang side:
2023/02/14 11:37:30 Client started, loops 39, rest: 3100, total: 162844 2023/02/14 11:37:30 2023-02-14 11:37:30.895731 +0100 CET m=+682.737986668 Connected to server 2023/02/14 11:37:30 1.065167ms Disconnected from server 2023/02/14 11:37:30 Cannot close the connection: close tcp 127.0.0.1:56007->127.0.0.1:3005: use of closed network connection Downloaded integrations/downloadDir/crm_1 162814 bytes outside
Additional information
this consistently fails like every 10th try. just no close by bun.