CppServer icon indicating copy to clipboard operation
CppServer copied to clipboard

Can you recommend a technique for deferring a response to another thread?

Open jbroll opened this issue 4 years ago • 3 comments

I'm wondering if you could suggest a strategy to defer a response to another thread. Consider where a response is expensive and needs to be computed. I don't want to block the service threads. Since the onReceivedRequest is a method of HttpSession I can't take a reference to its shared_ptr and ensure it's continued existence if the client closes the other end and the session is disconnected.

I've worked around that by making a subclass of HttpSession that contains a reference to the shared pointer returned by HttpServer::CreateSession(). It's a hack but mostly works.

An additional issue that will result if I'm holding a reference to the session is a race when a client disconnects on timeout and before onDisconnect is called. The deferred response might become available and be written to the file descriptor that has since been opened to a new client, thus passing data to a client unrelated to the original session.

jbroll avatar Aug 14 '20 18:08 jbroll

CC: @chronoxor

mbasmanova avatar Aug 17 '20 14:08 mbasmanova

@chronoxor Is this something you can advise on? I'm also seeing that the project has no PRs open or closed. I wonder how bugs are fixed and improvements being made.

mbasmanova avatar Sep 10 '20 08:09 mbasmanova

CC: @chronoxor

giosh04 avatar May 04 '23 10:05 giosh04