-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EngineIO Panic #166
Comments
Hey ;) Thanks for using the library! Could you maybe give more information on your Client and Server setup? I can't really find something from the stack trace that gives a clear indication of what went wrong, besides the fact that it happened during connection. Generally I would think that has something to do with the underlying network connection. |
I am using the python-implementation with FastAPI (asgi-mount), which works perfectly fine in production. The Python-client also doesn't crash with this server. An unstable connection can't be possible because of local host. In the next days I'll try the same thing with the js-client and see if the error also occurs there. By the way: until it panicks, it works perfectly fine. |
Oke, I tried to setup a local example and used the following code which ran through all right: Server: from fastapi import FastAPI
from fastapi_socketio import SocketManager
app = FastAPI()
sio = SocketManager(app=app, cors_allowed_origins=["*"], mount_location='/')
@app.sio.on('join')
async def handle_join(sid, *args, **kwargs):
await sio.emit('lobby', 'User joined')
@sio.on('test')
async def test(sid, *args, **kwargs):
await sio.emit('hey', 'joe')
if __name__ == '__main__':
import logging
import sys
logging.basicConfig(level=logging.DEBUG,
stream=sys.stdout)
import uvicorn
uvicorn.run("foo:app", host='0.0.0.0', port=4200, reload=True, debug=False) Client: fn main() -> Result<(), Error> {
let url = Url::parse("http://localhost:4200/socket.io/").unwrap();
let socket = ClientBuilder::new(url)
.on("hey", |msg, _| match msg {
Payload::String(str) => println!("Received string: {}", str),
Payload::Binary(bin) => println!("Received binary data: {:#?}", bin
})
.connect()?;
let payload = json!({"token": 123});
let result = socket.emit("test", Payload::String(payload.to_string()));
assert!(result.is_ok());
sleep(Duration::from_secs(2));
assert!(socket.disconnect().is_ok());
Ok(())
} I don't know how confidential your code is, but if you struggle to find the error don't mind sending me the code via mail ;) |
The code is over here: https://github.com/mawoka-myblock/sd-replacement/tree/rewrite. The code producing the error is located in the |
The Dart-client doesn't have these problems. |
The problem is still there, also if I use your example, but now the stacktrace is empty.
I've also tried the stable compiler, same problem. |
I am sorry but the executor code doesn't even compile:
|
I've seen and fixed it, so that wasn't the problem. Added some imports and the one |
Also my example still runs fine. What compiler version are you on? (running rustc --version) - The example runs fine on |
Did you commit that change? I can't debug your executor. |
Nope...
For me, rust version |
What target are you compiling for? (please run |
|
For me (aarch64-apple-darwin) the example works on 1.59. |
this sounds alright.... weird that the example throws the error for you... |
Ah the input bot doesn't compile for me as it's not available for MacOS. |
Good to know! Can you run the linux-binary on your mac (Intel)? |
Apparently not... I am sorry that I can't help you here. What error do you see when you execute my example client? Does anything after |
At first, I increased the sleep to 10s, because the error occurs only after ~8 seconds. Then, It just connects to the server and does nothing (with is fine since it's waiting). Then it suddenly panics without a stacktrace sometimes. |
I've also tried the same thing on another linux machine seconds ago and it's completely the same error (Nightly compiler). Stable compiler is the same. |
What now? |
I added some debug logging on a different branch, could you please add the dependency as like: |
That's the new error! |
Oke, this error originates from an invalid packet send by the server... that's weird... |
Let me quickly write a nodejs socket-server! |
The node-server doesn't seem to have the problem. const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
socket.on("server_connect", (data) => {
console.log(data);
socket.join("1");
})
socket.on("execute", (data) => {
console.log(data);
socket.to("1").emit("execute", data);
})
});
server.listen(8000, () => {
console.log('listening on *:8000');
}); |
Mh... weird... I am currently trying the example in an Ubuntu VM |
Oke the example worked on the following (virtual) machine:
I really don't have any idea where that error comes from and why it only appears on your machine... |
Could you trace the messages via Wireshark? That might help to find the malicious packet... |
I will try :D |
Did you also run the same server as I did for my example? |
Nope. I've used the following one, but the error also occurred with your server. import json
import socketio
from server.config import settings
from hashlib import sha256
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins=["*", "https://amritb.github.io"])
def get_room_name(phrase: str) -> str:
return sha256(f"{phrase}-{settings.secret_key}".encode()).hexdigest()
@sio.on('*')
async def catch_all(event, sid, data):
print(f"{sid} {event} {data}")
@sio.event
async def server_connect(sid: str, data: dict[str, str] | str):
if type(data) is str:
data = json.loads(data)
print(sid, )
phrase = data["phrase"]
word_list = phrase.split(" ")
print(f"{sid} connected with {phrase} and {word_list}")
if len(word_list) != 5:
print("wrong number of words")
await sio.emit("on_error", {"message": "wrong phrase"}, room=sid)
return
async with sio.session(sid) as session:
session["phrase"] = phrase
sio.enter_room(sid, get_room_name(phrase))
@sio.event
async def execute(sid, data):
phrase = (await sio.get_session(sid))["phrase"]
print(data, "Execute!")
await sio.emit("execute", data, room=get_room_name(phrase)) |
Sent it via mail! |
I am no python expert, how do you start the server in this example? |
Sorry, I've mounted it in a different file, the following should be "startable" with import json
import socketio
from server.config import settings
from hashlib import sha256
from fastapi import FastAPI
from socketio import ASGIApp
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins=["*", "https://amritb.github.io"])
def get_room_name(phrase: str) -> str:
return sha256(f"{phrase}-{settings.secret_key}".encode()).hexdigest()
@sio.on('*')
async def catch_all(event, sid, data):
print(f"{sid} {event} {data}")
@sio.event
async def server_connect(sid: str, data: dict[str, str] | str):
if type(data) is str:
data = json.loads(data)
print(sid, )
phrase = data["phrase"]
word_list = phrase.split(" ")
print(f"{sid} connected with {phrase} and {word_list}")
if len(word_list) != 5:
print("wrong number of words")
await sio.emit("on_error", {"message": "wrong phrase"}, room=sid)
return
async with sio.session(sid) as session:
session["phrase"] = phrase
sio.enter_room(sid, get_room_name(phrase))
@sio.event
async def execute(sid, data):
phrase = (await sio.get_session(sid))["phrase"]
print(data, "Execute!")
await sio.emit("execute", data, room=get_room_name(phrase))
app = FastAPI()
app.mount("/", ASGIApp(sio)) |
Hey @mawoka-myblock, can you confirm that the error is gone with version 0.3.1? ;) |
I am so sorry to tell you, that it didn't fix my bug, although the panic comes even later (probably because of the node server)... |
No way really? I am going to take a look again. Anyhow I fixed another bug, that's for sure :D |
Oke are you sure you've set the right version in your Cargo.toml (0.3.1)? I don't get an error when being connected... |
Yes, but the panic occurs after half an hour or even later! |
I've just noticed: The issue that occurs only after half an hour, could also be render shutting down. I'll keep you up-to-date |
Any news? This implementation generally doesn't automatically reconnect on errors (like e.g. the JS implementation) instead it throws an error. This might happen if the underlying transport unexpectedly resets connection. |
The error is exactly the same
I don't know if the connection gets interrupted, but why should it get interrupted? |
Any update on this issue? I have the same thing happening to me. |
Yea, this issue has never been solved... |
Wrapping the socket inside a |
I a using your great library, but my applications panics after some time (seems to be random ~10-30 secs after startup) with the following backtrace:
It's probably just me, doing something completely wrong, but I think that it still shouldn't panic.
Thanks for your help!
The text was updated successfully, but these errors were encountered: