Skip to content
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

background processing some submits go missing #161

Open
HumptyNumpty opened this issue Jul 7, 2020 · 0 comments
Open

background processing some submits go missing #161

HumptyNumpty opened this issue Jul 7, 2020 · 0 comments
Labels
bug 🪲 Something isn't working

Comments

@HumptyNumpty
Copy link

HumptyNumpty commented Jul 7, 2020

It would appear some submitted jobs are not being processed
The same problem occurs if the sleep statement is replaced by a compute bound task - discard sum(toSeq(0 .. 100_000_000))
Silly code below

serving
new req 1
new req 2
new req 3
processing job 1
new req 4
new req 5
new req 6
processing job 2
processing job 3
new req 7
processing job 4
processing job 6
processing job 7

#Code

import
    asynchttpserver,
    asyncdispatch,
    std/[atomics, os],
    weave


# ctrl-c interupt handling
type EKeyboardInterrupt = object of OSError

 
proc handler() {.noconv.} =
    raise newException(EKeyboardInterrupt, "Keyboard Interrupt")
 
setControlCHook(handler)


# GLOBALS
var shutdownWeave: Atomic[bool]
shutdownWeave.store(false, moRelaxed)

var executorThread: Thread[ptr Atomic[bool]]
executorThread.runInBackground(Weave, shutdownWeave.addr)

var reqnum: int


# fn submit to weave
proc display_int(x: int): bool =
    sleep(1000)
    echo "processing job " & $x
    return true


# request callback
proc cb(req: Request) {.async.} =
    inc(reqnum)

    echo "new req " & $reqnum
    let ok = submit display_int(reqnum)
    
    await req.respond(Http200, "Hello World " & $reqnum)


proc serve() =    
    setupSubmitterThread(Weave)
    waitUntilReady(Weave)

    var server = newAsyncHttpServer()
    waitFor server.serve(Port(8080), cb)


proc cleanup() = 
    echo "\n\rcleaning up"
    echo "shutting down weave"
    shutdownWeave.store(true)
    

when isMainModule:

    echo "serving"
    try:
        serve()
    except EKeyboardInterrupt:
        cleanup()

    echo "end"
@mratsim mratsim added the bug 🪲 Something isn't working label Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants