I've now got some slightly less trivial async code I'm trying to get to run, 
using the 'news' WebSockets module. The compiler complains that my HTTP handler 
isn't gcsafe, and suggests "Annotate the proc with {.gcsafe.} to get extended 
error information."

However,

  1. I can't see how my code isn't GC-safe, since it has no global variables 
whatsoever.
  2. If I add the `gcsafe` pragma to my callback proc, it now compiles without 
errors! Where's my "extended error information"?


    
    
    import blip
    import news, asyncdispatch, asynchttpserver
    
    when isMainModule:
        echo("Starting Blip server on port 9001...")
    
    var server = newAsyncHttpServer()
    proc cb(req: Request) {.async.} =
        if req.url.path == "/blipsync":
            var ws = await newWebsocket(req)
            echo "Creating new Blip"
            var blip = newBlip(ws)
            await blip.run()   # <-- this line triggers the gcsafe error
            echo "...Closed Blip"
        await req.respond(Http404, "Nope", newHttpHeaders())
    
    waitFor server.serve(Port(9001), cb)
    
    
    Run

If I take out the line `await blip.run()`, the error goes away. But neither 
that function nor anything it calls appears to involve any global state. (It's 
too much code to post here in the forum, unless someone really wants me to!)

Did adding the `{.gcsafe.}` pragma silence a false alarm? Or is it suppressing 
a genuine problem that will cause thread-safety issues?

Thanks!

—Jens

Reply via email to