adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 127 forks source link

WebSocket: Socket select error: An invalid argument was supplied #276

Closed andre2007 closed 3 years ago

andre2007 commented 3 years ago

WebSocket client is raising error Socket select error: An invalid argument was supplied.

I reduced it to this coding: (While it says version 9.1.2, it is actually master)

/+ dub.sdl:
    name "app"
    dependency "arsd-official:http" version="9.1.2"
+/

import http2;

void main()
{
    auto ws = new WebSocket(Uri("ws://localhost:8765"));
    ws.connect();
    WebSocket.eventLoop();
}

Python:

import asyncio
import websockets

async def hello(websocket, path):
    name = await websocket.recv()
    print(f"< {name}")
    greeting = f"Hello {name}!"
    await websocket.send(greeting)
    print(f"> {greeting}")

start_server = websockets.serve(hello, "localhost", 8765)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
adamdruppe commented 3 years ago

I betcha it is just the connection timing out since it never sends. Phobos doesn't detect Windows timeouts right. That seems to be what I'm seeing on Wine, lemme try my laptop too.

You compiling for Windows 64 bit?

andre2007 commented 3 years ago

Yes, compiling for windows x86_64.

One observation from my real application: onOpen and onClose is called fine (writeln debug) if there is no data sent back from server to client.

In case there is data, the error is thrown after onOpen is called.

adamdruppe commented 3 years ago

I think I just found it, I handled timeout Unix style with a direct retry, but on Windows a timeout requires the ReadSet to be reconstructed. Just pushed to master, see if it works well for you now.

adamdruppe commented 3 years ago

I also changed the openssl load because my test rig didn't have the dlls, it should work better now but lmk if that broke too.

andre2007 commented 3 years ago

Thanks a lot :) This solved the issue.