about summary refs log tree commit homepage
path: root/lib
DateCommit message (Collapse)
2009-04-01unicorn 0.4.1 v0.4.1
2009-04-01cgi_wrapper: HTTP status code cleanups
The default status was 404 in Mongrel and this is needed to work with older versions of Rails. Additionally parse the "Status:" header if it ever got set and the actual "status" code passed to CGI::headers was not set.
2009-04-01cgi_wrapper: fix cookies and other headers
The @output_cookies instance variable was being ignored, and some versions of Rails uses that. Additionally, cleanup multi-value headers in general to avoid dropping headers.
2009-03-31Use {read,write}_nonblock on the pipe
Instead of trusting sysread/syswrite to throw EAGAIN if the pipe is full (highly unlikely); just use non-blocking methods which are indeed non-blocking and don't care for the #blocking= method added to it.
2009-03-31configurator: remove unnecessary SocketHelper include
2009-03-31Better canonicalization of listener paths + tests
* Expand addresses like "1:8080" to "127.0.0.1:8080" beforehand so sock_name() in SocketHelper will always return consistent results. * Add support for "unix:/path/to/foo" paths for easier synchronization with nginx config files.
2009-03-30cgi_wrapper: ensure "Status:" header is not set
Rack does not like it; instead try to set it as the @status code if possible.
2009-03-30app/old_rails/static: define missing constant
REQUEST_METHOD got removed from Unicorn::Const and this module is the only place that currently uses it.
2009-03-29Fix default listener setup
Combining command-line and config file options in a reasonable manner has and always will be a painful experience.
2009-03-29Avoid having two pid files pointing to the same pid
It makes test_exec more reliable and probably helps other scripts people may run around this.
2009-03-29http11: use :http_body instead of "HTTP_BODY"
"HTTP_BODY" could conflict with a "Body:" HTTP header if there ever is one. Also, try to hide this body from the Rack environment before @app is called since it is only used by Unicorn internally.
2009-03-29configurator: favor "listen" directive over "listeners"
We still need to support "listeners" for easy use of command-line options, but folks using the config file should use "listen" as it is more flexible.
2009-03-29configurator: per-listener backlog, {rcv,snd}buf config
Instead of having global options for all listeners, make all socket options per-listener. This allows reverse-proxies to pick different listeners to get different options on different sockets. Given a cluster of machines (10.0.0.1, 10.0.0.2, 10.0.0.3) running Unicorn with the following config: ------------------ 8< ---------------- listen "/tmp/local.sock", :backlog => 1 listen "*:8080" # use the backlog=1024 default ------------------ 8< ---------------- It is possible to configure a reverse proxy to try to use "/tmp/local.sock" first and then fall back to using the TCP listener on port 8080 in a failover configuration. Thus the nginx upstream configuration on 10.0.0.1 to compliment this would be: ------------------ 8< ---------------- upstream unicorn_cluster { # reject connections ASAP if we are overloaded server unix:/tmp/local.sock; # fall back to other machines in the cluster via "backup" # listeners which have a large backlog queue. server 10.0.0.2:8080 backup; server 10.0.0.3:8080 backup; } ------------------ 8< ---------------- This removes the global "backlog" config option which was inflexible with multiple machines in a cluster and exposes the ability to change SO_SNDBUF/SO_RCVBUF via setsockopt(2) for the first time.
2009-03-27Always try to send a valid HTTP response back
This reworks error handling throughout the entire stack to be more Ruby-ish. Exceptions are raised instead of forcing the us to check return values. If a client is sending us a bad request, we send a 400. If unicorn or app breaks in an unexpected way, we'll send a 500. Both of these last-resort error responses are sent using IO#write_nonblock to avoid tying Unicorn up longer than necessary and all exceptions raised are ignored. Sending a valid HTTP response back should reduce the chance of us from being marked as down or broken by a load balancer. Previously, some load balancers would mark us as down if we close a socket without sending back a valid response; so make a best effort to send one. If for some reason we cannot write a valid response, we're still susceptible to being marked as down. A successful HttpResponse.write() call will now close the socket immediately (instead of doing it higher up the stack). This ensures the errors will never get written to the socket on a successful response.
2009-03-27Remove needless line break
2009-03-27No need to disable luserspace buffering on client socket
Unicorn always uses lower-level sys{read,write} methods when doing I/O so setting "client.sync=true" is just a wasted operation.
2009-03-27style: symbols instead of strings for signal names
They're easier for me to type and read and just barely faster when doing comparisons on.
2009-03-27Deferred log rotation in workers
Instead of rotating logs immediately when SIGUSR1 is caught, defer it until the current client is processing is complete. This allows multi-line log messages generated by apps to not be broken up if SIGUSR1 is received while the app is running. If we're sleeping inside IO.select, we close a pipe in the exceptfds set to cause EBADF to be raised. This also adds a small reliability improvement to test_exec so we wait until signals are ready before sending USR1 to rotate logs.
2009-03-26Don't allow failed log rotation to to break app
In case there are permissions problems that cause log rotation to fail, we trap the error and defer death until the current request finishes running.
2009-03-25Merge commit 'v0.2.3'
* commit 'v0.2.3': unicorn 0.2.3 Ensure Tempfiles are unlinked after every request Don't bother unlinking UNIX sockets Conflicts: lib/unicorn/socket.rb
2009-03-25unicorn 0.2.3 v0.2.3
2009-03-25Ensure Tempfiles are unlinked after every request
Otherwise we bloat TMPDIR and run the host out of space, oops!
2009-03-25Don't bother unlinking UNIX sockets
Since we always unlink existing sockets when binding, there's no point in having code to unlink the sockets when we exit. Additionally, the old code path was racy.
2009-03-25Socket: add {snd,rcv}buf opts to bind_listen
bind_listen takes a hash as its second parameter now, allowing the addition of :sndbuf and :rcvbuf options to specify the size of the buffers in bytes. These correspond to the SO_SNDBUF and SO_RCVBUF options via setsockopt(2) respectively. This also adds support for per-listener backlogs to be used. However, this is only an internal API change and the changes have not yet been exposed to the user via Unicorn::Configurator, yet. Also add a bunch of SocketHelper tests
2009-03-24simplify the HttpParser interface
This cuts the HttpParser interface down to #execute and #reset method. HttpParser#execute will return true if it completes and false if it is not. http->nread state is kept internally so we don't have to keep track of it in Ruby; removing one parameter from #execute. HttpParser#reset is unchanged. All errors are handled through exceptions anyways, so the HttpParser#error? method stopped being useful. Also added some more unit tests to the HttpParser since I know some folks are (rightfully) uncomfortable with changing stable C code. We now have tests for incremental parsing. In summary, we have: * more test cases * less C code * simpler interfaces * small performance improvement => win \o/
2009-03-24HttpRequest: small improvement for GET requests
Most HTTP requests are GET requests and the majority of those GET requests are complete after one sysread. This is especially true since we're optimized for fast clients. So short the extra checks and trust our HTTP parser implementation to do the right thing (we have decent unit tests for it).
2009-03-23unicorn_rails: support non-Rack versions of Rails
This resurrects old code from Mongrel to wrap the Rails Dispatcher for older versions of Rails. It seems that Rails >= 2.2.0 support Rack, but only >=2.3 requires it. I'd like to support Rails 1.2.x for a while, too.
2009-03-22Don't bother unlinking UNIX sockets
Since we always unlink existing sockets when binding, there's no point in having code to unlink the sockets when we exit. Additionally, the old code path was racy.
2009-03-22Streamline rack environment generation
Ensure constants are used as hash keys and cleanup unused constants. This gives a 10-15% improvement with test/benchmark/request.rb
2009-03-22HttpResponse: speed up non-multivalue headers
The extra split slows things down a little as as it generates an array with a new string value and adds an extra loop to iterate through.
2009-03-22unicorn 0.2.2 v0.2.2
2009-03-21Handle Rack multivalue headers correctly
Rack uses a single newline character to represent multi-value headers. Thus { 'Set-Cookie' => "foo=bar\nbar=foo" } will get you: Set-Cookie: foo=bar Set-Cookie: bar=foo While RFC2616 says you can combine headers as: Set-Cookie: foo=bar,bar=foo There are probably HTTP clients out there that don't handle things correctly so don't bother... Additionally, don't bother doing duplicate suppression anymore. Just assume Rack or a higher layer knows what it's doing regarding duplicates and we'll get a Hash most of the time anyways.
2009-03-21Simplify code for sleeping/waking up the master
Only sleep if our signal queue is empty. Remove redundant exception handling and go back to just consuming the entire pipe since that's more efficient if we're slammed with signals for whatever reason.
2009-03-21Rotate master logs before workers.
The master _may_ run with different user/group/umask than the workers. Since the logs were always created by the master process, the master should rotate them first to ensure correct ownership and permissions. This way if the workers fail log rotation and die, they'll be automatically respawned with the new logs in place.
2009-03-21HttpRequest: correctly reference logger
2009-03-21http11: don't set headers Rack doesn't like
Fix the logic in HttpParser up front so we don't have to mess around with the following convoluted steps: 1. setting the HTTP_CONTENT_{LENGTH,TYPE} headers 2. reading the HTTP_CONTENT_{LENGTH,TYPE} headers again 3. setting the CONTENT_{LENGTH,TYPE} based on the HTTP_-prefixed one 4. deleting the HTTP_CONTENT_{LENGTH,TYPE} headers (since Rack doesn't like them) 1, 2, 3 were in the C code, 4 was in Ruby. Now the logic is: 1. if CONTENT_{LENGTH,TYPE} headers are seen, don't prefix with "HTTP_". All the branch logic for the new code is done at init time, too so there's no additional overhead in the HTTP parsing phase. There's also no additional overhead of hash lookups in the extra steps.
2009-03-20Process management cleanups
* Use waitpid2 to more reliably trap exit status * Stop including Process namespace since it leads to confusing conflicts.
2009-03-20Add Unicorn::App::ExecCgi
This is a Rack handler that passes Rack::Lint running cgit and so it has been lightly tested. No other CGI executables have been run with it.
2009-03-20HttpResponse: close body if it can close
The body could be an IO object that is closeable. So make sure we close it if it can be closed to avoid file descriptor leakage.
2009-03-19Trap WINCH to QUIT children without respawning
This will only be enabled if we're daemonized and "real" WINCH signals cannot be generated by resizing the terminal. This is to avoid confusing developers who run in the foreground of a terminal. Additionally document procedures for reexecuting a running binary.
2009-03-19Move listen path and address expansion to Configurator
This fixes a bug where listener names in the master process would be incorrectly matched with the existing set; causing UNIX sockets to be unbound and rebound; breaking things for child processes. This is a better fit anyways since it's higher level.
2009-03-19start libifying common launcher code
The daemonization logic between unicorn and unicorn_rails scripts can definitely be shared. Again: our daemonization logic is slightly non-standard since our executables are designed to run in APP_ROOT/RAILS_ROOT and not "/" like "normal" UNIX daemons.
2009-03-18unicorn v0.2.1, fix the Manifest v0.2.1
2009-03-18unicorn 0.2.0 v0.2.0
2009-03-18Add signal queueing for test reliability
Although I didn't like the idea initially, signal queueing allows test_exec to run more reliably and the limited signal queue size will prevent scary queued signal behavior. Also, always wakeup the master immediately when CHLD is trapped to reduce the performance impact of SIGHUP-based config reloading. Combined with an extra check in test_exec, this should make test_exec run much more reliably than before.
2009-03-18gracefully die if working dir is invalid at fork
In nearly every app, if the current working directory disappears, the app becomes broken, sometimes subtly. It can be especially broken when preload_app is false (the default). So just shut ourselves down to spare ourselves the wasted CPU cycles on a dead app. As a (hopefully) pleasant side effect, this allows configurations with preload_app==false (the default) to do application code reloads via SIGHUP (in addition to unicorn config reloads).
2009-03-17Allow binding to UNIX sockets relative to "~"
This is to be consistent with the existing "pid" and std{err,out}_path options which also take paths relative to "~"
2009-03-10HttpRequest: update comment regarding short writes v0.1.0
Or lack thereof on POSIX.
2009-03-10HttpRequest: set binmode on tempfiles
Just in case this stupid Ruby 1.9-ism creeps up on someone; I haven't been able to reproduce I/O corruption from the test cases, but better safe than sorry here.
2009-03-09Configurator: document reasons for lowering backlog