Comments (8)
Oh! Thank you, this is indeed where the issue lies. Thanks for your kind help!
from ws.
Hey, which version do you use?
from ws.
Hey, which version do you use?
Hi!. It is gobwas/ws v1.3.0
github.com/gobwas/ws v1.3.0
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
from ws.
Looks like the connection is closed on Binance side due to error in the payload, see message:
Received message: {"id":"1714803365000","status":400,"error":{"code":-1000,"msg":"Missing required 'method' in JSON request."}}
from ws.
Looks like the connection is closed on Binance side due to error in the payload, see message:
Received message: {"id":"1714803365000","status":400,"error":{"code":-1000,"msg":"Missing required 'method' in JSON request."}}
Hi! Mr. Kovalov,
I think I sent only one "ping" request and received a correct 200 response, as expected. However, I later received a 400 response indicating that the method was missing. I was confused.
I actually used gobwas‘ ”dialer.Dial“ function to connect to this address and establish a WebSocket connection. However, as soon as the connection is established, it gets disconnected, and I keep receiving EOF. This issue only occurs with this specific address; other addresses work fine. The original codebase is quite extensive, with many layers of abstraction. I spent an entire day troubleshooting but couldn't pinpoint the problem.
To validate, I tried using gorilla/websocket as a comparison, and I didn't encounter a similar issue. That's why I created this simple test code in the issue to see if I can reproduce this bug.
from ws.
Check the 2nd if
in 1st goroutine. You send back what you've received from Binance:
{"id":"1714824103000","status":200,"result":{},"rateLimits":[{"rateLimitType":"REQUEST_WEIGHT","interval":"MINUTE","intervalNum":1,"limit":2400,"count":12}]}
In this payload there is no requested field 'method' as Binance says. Do you've a gorilla/websocket
reproducer that does exactly the same steps and receive something else in a response?
from ws.
Do you've a
gorilla/websocket
reproducer that does exactly the same steps and receive something else in a response?
Hi,
Yes, I tried the same code on Gorilla/WebSocket, and it seems to be working fine.
Code
func TestGorillaWs(t *testing.T) {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
// WebSocket地址
//url := "wss://stream.binance.com:9443/ws/btcusdt@depth"
url := "wss://ws-fapi.binance.com/ws-fapi/v1"
// 连接到WebSocket地址
c, _, err := websocket.DefaultDialer.Dial(url, nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
done := make(chan struct{})
go func() {
defer close(done)
for {
_, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
fmt.Printf("Received: %s\n", message)
}
}()
go func() {
for {
ts := fmt.Sprintf("%d", time.Now().Unix()*1000)
pingMsg := map[string]interface{}{
"id": ts,
"method": "ping",
}
msg, err := json.Marshal(pingMsg)
if err != nil {
log.Println("json marshal error:", err)
return
}
err = c.WriteMessage(websocket.TextMessage, msg)
if err != nil {
log.Println("write ping message error:", err)
}
time.Sleep(5 * time.Second)
}
}()
select {}
}
output:
Running tool: /home/ubuntu/go/bin/go test -timeout 30s -run ^TestGorillaWs$
=== RUN TestGorillaWs
Received: {"id":"1714825512000","status":200,"result":{},"rateLimits":[{"rateLimitType":"REQUEST_WEIGHT","interval":"MINUTE","intervalNum":1,"limit":2400,"count":6}]}
Received: {"id":"1714825517000","status":200,"result":{},"rateLimits":[{"rateLimitType":"REQUEST_WEIGHT","interval":"MINUTE","intervalNum":1,"limit":2400,"count":7}]}
Received: {"id":"1714825522000","status":200,"result":{},"rateLimits":[{"rateLimitType":"REQUEST_WEIGHT","interval":"MINUTE","intervalNum":1,"limit":2400,"count":8}]}
Received: {"id":"1714825527000","status":200,"result":{},"rateLimits":[{"rateLimitType":"REQUEST_WEIGHT","interval":"MINUTE","intervalNum":1,"limit":2400,"count":9}]}
Received: {"id":"1714825532000","status":200,"result":{},"rateLimits":[{"rateLimitType":"REQUEST_WEIGHT","interval":"MINUTE","intervalNum":1,"limit":2400,"count":10}]}
Received: {"id":"1714825537000","status":200,"result":{},"rateLimits":[{"rateLimitType":"REQUEST_WEIGHT","interval":"MINUTE","intervalNum":1,"limit":2400,"count":11}]}
from ws.
As mentioned above: You've an explicit send of received data:
if err := wsutil.WriteClientMessage(conn, op, msg); err != nil {
log.Printf("failed to write message: %v", err)
break
}
Tried to add similar code in gorilla/websocket
example and it will fail:
err = c.WriteMessage(websocket.TextMessage, message)
if err != nil {
log.Println("write ping message error:", err)
}
from ws.
Related Issues (20)
- Question: client example
- EOF error on ws.Upgrade HOT 8
- Is it necessary to use sync.Pool to reuse Reader Object in readData? HOT 1
- Read and Write timeouts? HOT 5
- Handshake.Extentions pointing to a buffer already returned to pbufio.ReaderPool
- State of the package and security updates HOT 6
- Websocket error on Safari HOT 4
- Dialer's Header parameter doesn't work as intended HOT 6
- Is WriteServerMessage thread-safe? HOT 9
- json decoder or unmarshaler? HOT 2
- Client-side example? HOT 5
- readme example problem HOT 1
- Correct way to handle continuation frame? HOT 1
- ReadFrame maxs out at 4096 lengths HOT 11
- RSV1 set, FIN not set on control using wsutil HOT 1
- Question - add headers during the upgrade HOT 2
- message rate limiter HOT 1
- Any example for using this library with `gnet`? HOT 5
- I encountered a problem of automatic disconnection after 30 seconds HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ws.