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

document setTimeout guarantees #186

Open
aycanirican opened this issue Jan 5, 2014 · 2 comments
Open

document setTimeout guarantees #186

aycanirican opened this issue Jan 5, 2014 · 2 comments
Assignees

Comments

@aycanirican
Copy link

Consider this simple handler:

fooHandler :: Snap ()
fooHandler = do
  setTimeout 1
  liftIO $ threadDelay $ 3*1000*1000
  writeBS "Foo called"

We expect this handler throws an exception since we set 1 second timeout, our computation takes at least 3 seconds.

But it doesn't. It often throws exception, most of the time writes "Foo called" message.

@gregorycollins
Copy link
Member

This is working as intended -- the guarantee you get is that the timeout exception will be thrown at "some reasonable time" after the timeout expires, but not before. Currently the timeout manager is hard-coded to wake up at most once every five seconds.

If you want finer-grained control over timeouts (i.e. accuracy better than 5 seconds) then you'll have to use the stock Haskell System.Timeout stuff, but keep in mind that you'll be adding additional load to the GHC I/O manager by doing so.

P.S.: the design tradeoff may be different here as of GHC 7.8's MIO I/O manager, but relaxing the guarantee we offer for timeouts enables us to implement this feature a lot more cheaply under current GHC than otherwise would be possible -- and yes, that has an impact on scalability.

@gregorycollins
Copy link
Member

Re-opening to remind me to document in the docstrings what the timeout functionality does and what its limitations are, i.e. if you want accurate millisecond-level guarantees for an RPC server, you'll have to implement them in some other way.

In snap-server 1.0 you will have the option of implementing this using server hooks -- the user can pass in IO actions that run during the various phases of the request/response lifecycle. The currently released snap-server only gives you visibility into the snap monad and response sending phases.

@gregorycollins gregorycollins reopened this Jan 7, 2014
@ghost ghost assigned gregorycollins Jan 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants