niv / websocket.nim

websockets for nim
http://niv.github.io/websocket.nim/docs/0.1.1/websocket.html
Other
101 stars 25 forks source link

reqPing makes code not gcsafe, fails to compile #21

Closed luked99 closed 6 years ago

luked99 commented 6 years ago

If I try to compile a simple example which uses readData() using nim 0.17.2, it fails with:

Error: type mismatch: got (AsyncHttpServer, Port, proc (req: Request): Future[system.void]{.locks: <unknown>.})
but expected one of:    
proc serve(server: AsyncHttpServer; port: Port;       
          callback: proc (request: Request): Future[void]; address = ""): Future[void]

The problem seems to be the use of reqPing, which is a global variable and makes the async function not thread safe.

Here's the code I'm using (call to verifyWebsocketRequest() omitted for clarity).

var server = newAsyncHttpServer()

proc cb(req: Request) {.async.} =
    var f = await req.client.readData(false)
    echo $f

waitfor server.serve(Port(8080), cb)
Araq commented 6 years ago

Was fixed by your PR.