hi,
I've encounter a strange problem when running this:
get '/' do
sleep 32
'hello world'
end
and problem is, the browser get nothing.
the magic number 32, is searched by binary_search(-_-b), when it get
smaller, the browser works happy.
Then I change the number to 60 and use tcpdump to check what
happens. It seems that Thin close connection about 30s after it
receive the request, then it log normally as if it send back the
response ..
I can't find relative config about this timeout ..
Not sure what you are trying to do, but Thin runs requests within an
EventMachine reactor thread, so sleep is not a good thing to do.. it
will block other requests too while sleeping.
If `sleep 32` is intended to represent a long-running task, you could
do something like
get '/' do
EM.defer { sleep 32 }
'hello world, waiting for task to end'
end
which offloads the task to a different thread. But this is for the
most simplistic cases - in most cases you want to send a response
during/after the long-running task. In those cases the Sinatra stream
helper is your best bet.
get '/' do
stream do |out|
11.times do |i|
sleep(2)
out << 'hello world'[i]
end
end
end
On Feb 19, 7:29 am, ranc <rancp...@gmail.com> wrote:
> hi,
> I've encounter a strange problem when running this:
> get '/' do
> sleep 32
> 'hello world'
> end
> and problem is, the browser get nothing.
> the magic number 32, is searched by binary_search(-_-b), when it get
> smaller, the browser works happy.
> Then I change the number to 60 and use tcpdump to check what
> happens. It seems that Thin close connection about 30s after it
> receive the request, then it log normally as if it send back the
> response ..
> I can't find relative config about this timeout ..
Let me know if the README is not sufficient. I haven't jumped into the sinatra codebase to see if there is a better way around this, but this might work for you.
On Sun, Feb 19, 2012 at 6:29 AM, ranc <rancp...@gmail.com> wrote: > hi, > I've encounter a strange problem when running this:
> get '/' do > sleep 32 > 'hello world' > end > and problem is, the browser get nothing. > the magic number 32, is searched by binary_search(-_-b), when it get > smaller, the browser works happy.
> Then I change the number to 60 and use tcpdump to check what > happens. It seems that Thin close connection about 30s after it > receive the request, then it log normally as if it send back the > response ..
> I can't find relative config about this timeout ..
> -- > You received this message because you are subscribed to the Google Groups "sinatrarb" group. > To post to this group, send email to sinatrarb@googlegroups.com. > To unsubscribe from this group, send email to sinatrarb+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.
Sorry to bother, but it's solved now ;)
I employ thin server directly rather than start the application with
"ruby myapp.rb".
The configure of thin server allows to set the server timeout, and
execution start point of ruby script(myapp.rb in this case).
If sinatra provide the configure of server timeout, things will be
easier, though
On Feb 19, 8:29 pm, ranc <rancp...@gmail.com> wrote:
> hi,
> I've encounter a strange problem when running this:
> get '/' do
> sleep 32
> 'hello world'
> end
> and problem is, the browser get nothing.
> the magic number 32, is searched by binary_search(-_-b), when it get
> smaller, the browser works happy.
> Then I change the number to 60 and use tcpdump to check what
> happens. It seems that Thin close connection about 30s after it
> receive the request, then it log normally as if it send back the
> response ..
> I can't find relative config about this timeout ..
thin is evented, you should never ever pause it's event loop, the server will not be able to server other requests while it's paused. That said you can change the timeout with the -t flag eg:
On Sun, Feb 19, 2012 at 13:29, ranc <rancp...@gmail.com> wrote: > hi, > I've encounter a strange problem when running this:
> get '/' do > sleep 32 > 'hello world' > end > and problem is, the browser get nothing. > the magic number 32, is searched by binary_search(-_-b), when it get > smaller, the browser works happy.
> Then I change the number to 60 and use tcpdump to check what > happens. It seems that Thin close connection about 30s after it > receive the request, then it log normally as if it send back the > response ..
> I can't find relative config about this timeout ..
> -- > You received this message because you are subscribed to the Google Groups "sinatrarb" group. > To post to this group, send email to sinatrarb@googlegroups.com. > To unsubscribe from this group, send email to sinatrarb+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.