Commit Graph

2321 Commits

Author SHA1 Message Date
Ævar Arnfjörð Bjarmason e0e8bb1932 psgi: Don't free the wsgi_req->async_environ atexit, only in request context
The atexit hooks can be called outside of the request context. See the
discussion at https://github.com/unbit/uwsgi/pull/772
2014-11-11 16:03:00 +00:00
Ævar Arnfjörð Bjarmason 0a27a334cb psgi: Remove the check for the async mode in uwsgi_perl_atexit
According to Roberto this is just copy/pasted from the Python code, see
1.0.1-289-gd7e8523.
2014-11-11 16:00:49 +00:00
Ævar Arnfjörð Bjarmason 1dcdb72054 psgi: Move the destruction of the perl interpreter to the atexit hook + more bugfixes
My previous commit ensured that we called the DESTROY hook but we
wouldn't properly call the atexit hook. Now when you start uWSGI as
instructed in that commit you'll get this:

 * localhost:1234?0:

   $$: Calling DESTROY

 * localhost:1234?1:

   *** psgix.harakiri.commit requested ***
   ...The work of process 523 is done. Seeya!
   523: Calling the atexit hook
   523: Calling DESTROY

 * Ctrl+C (or stop):

   ^CSIGINT/SIGQUIT received...killing workers...
   696: Calling the atexit hook

Before this change we wouldn't call the atexit hook when
psgix.harakiri.commit was requested by calling localhost:1234?1.

To make this work I removed the "if busy do not run atexit hooks"
condition added in 1.4-rc2-246-g499202e. Of course uWSGI is going to
think the worker is "busy", it's busy being destroyed, that doesn't mean
we should skip running the atexit hooks.

We'll still skip them under the "if hijacked do not run atexit hooks"
condition added in that commit, and the "managing atexit in async mode
is a real pain" condition added in 1.0.1-289-gd7e8523. Maybe those are
further bugs that need to be solved, but I don't know how to test those
modes.

Now we'll also call PERL_SET_CONTEXT() and PERL_SYS_TERM() appropriately
during destruction. Note that the latter should only be called once even
if you have multiple interpreters.
2014-11-11 13:09:05 +00:00
Ævar Arnfjörð Bjarmason 7ef33950c5 psgi: Ensure that we call any DESTROY hooks on psgix.harakiri.commit
Before this we'd just exit(0) and let the OS clean up after us, but
e.g. with post-buffering=1 we'll end up with a temporary file in /tmp
that we won't clean up when we exit unless DESTROY is called.

This resulted in us leaking files in /tmp if we ever had a request where
the last request before a harakiri was a POST request with a body we'd
buffer to /tmp.

We'd have similar leaks in any user-defined code that required DESTROY
to run.

Aside from this I'm still not very comfortable with what this whole code
here in psgi_plugin.c and psgi_loader.c is doing when managing the
interpreter(s). It:

 * Doesn't consistently call PERL_SET_CONTEXT() as described in "perldoc
   perlembed".

 * Nothing calls PERL_SYS_TERM() either.

 * Should we be calling uwsgi_perl_free_stashes() here too?

To test this:

    UWSGI_PROFILE=psgi python uwsgiconfig.py --build
    ./uwsgi --master --http-socket localhost:1234 --psgi t/perl/test_harakiri.psgi

Then elsewhere:

    curl 'localhost:1234?0'
    curl 'localhost:1234?1'

Both of those should emit "Calling DESTROY".
2014-11-10 18:57:52 +00:00
Riccardo Magliocchetti 2ab6c94da6 systemdlogger: fix compilation with -Werror=format-security 2014-11-06 11:00:32 +01:00
Unbit d0cb981cc9 fix php ZTS 2014-11-02 10:53:45 +01:00
Roberto De Ioris 48314cb903 use uwsgi_buffer for send_ack in #760 2014-11-02 09:32:50 +01:00
Roberto De Ioris 1964c9758b fixed #760 2014-11-02 06:43:17 +01:00
Mattia Barbon c6f6171910 Fix latent refcounting bug
It can be reproduced by enabling the Perl debugger inside a PSGI application:

    {
        package DB;

        sub DB { }
        sub sub { &$sub }
    }

    $^P = 0x73f;

    sub { [200, ['Content-Type' => 'text/plain'], ['Hello World']] }

For every request the following warnings are emitted:

    Attempt to free unreferenced scalar: SV 0xfea6e8, Perl interpreter: 0xd534a0.
    Attempt to free unreferenced scalar: SV 0xfea718, Perl interpreter: 0xd534a0.

where the unreferenced scalars are the uwsgi::input/uwsgi::error instances
created in build_psgi_env.

The calling convention for Perl subroutines is that the values pushed on the
stack must be mortalized in the callee, and if the caller wants to retain them,
it must do a SvREFCNT_inc to undo the effect of the mortalization.

Before this patch XS_input/XS_error were not mortalizing the value, and
uwsgi_perl_obj_new was not incrementing the reference count, so the two bugs
balanced each other.

When running under debugger, Perl forwards all function/method calls to
DB::sub, which causes a mortal copy of the return value of
uwsgi::input/error::new to be pushed on the stack. The value is cleared by the
FREETMPS at the end of uwsgi_perl_obj_new, and the freed value is added to the
environment hash. The warning is emitted at the end of the request when the
environment hash is freed and Perl notices that some of the values has been
already freed.
2014-11-01 21:05:54 +01:00
Mattia Barbon cdf2a24aa5 Remove unnecessary mortalization
newRV(sv_newmortal()) is equivalent to newRV_noinc(newSV(0)): the former
creates a new SV with refcount 1, schedules a decrement "soon" (the
mortalization) and increments the refcount, the net result is a refcount of 1,
which is what the latter does.
2014-11-01 20:43:37 +01:00
Riccardo Magliocchetti ca8ab125b4 Fixup forkpty ifdefery for dragonfly / freebsd
They are negated so we should AND them
2014-10-27 11:51:07 +01:00
Riccardo Magliocchetti afcb3e1001 Fixup pty compilation on hurd / dragonflybsd
Fix #756
2014-10-27 11:48:16 +01:00
Unbit 8053bb4cab ABI compatibility fixes 2014-10-24 17:14:27 +02:00
Unbit 00e0dcaa71 ABI compatibility with 2.0 2014-10-24 12:01:31 +02:00
Unbit 5953573c3b fix ssl shutdown management 2014-10-24 11:43:18 +02:00
trashnroll 7740edb604 Add gridfs bucket option. 2014-10-23 02:54:20 +04:00
Unbit bd07f82227 better management of rtsp requests 2014-10-21 09:01:59 +02:00
Roberto De Ioris 732ed3eb67 added automatic management of chunked input in http router 2014-10-19 12:52:11 +02:00
Unbit 04ad72ef44 fixed php SCRIPT_NAME usage when --php-app is in place 2014-10-18 04:20:21 +02:00
Unbit 635b37fea4 try to load trollius on python2 2014-10-17 13:04:17 +02:00
Nigel Heron 0aae7bdd73 fix heap corruption in carbon plugin 2014-10-16 17:31:32 -04:00
Unbit 0e8a30929e fixed #746 2014-10-15 10:07:16 +02:00
Greg Dahlman 3cd3559399 use _full write methods in rados plugin to truncate PUT request objects 2014-10-06 23:32:29 -07:00
Unbit 8e3c127e09 attempt to fix #732 2014-10-03 05:24:16 +02:00
Roberto De Ioris ffeefea93b preliminary support for RTSP 2014-09-29 11:56:11 +02:00
Unbit 202dc45519 getting rid of plugins still using ->pktsize 2014-09-21 08:49:04 +02:00
Unbit ed2ca5d333 request buffer_size is now 64bit (except for uwsgi protocol) 2014-09-21 08:26:20 +02:00
Unbit e2a29ee135 more robust asyncio 2014-09-20 09:07:13 +02:00
Unbit 26c9d2c618 fixed #701 2014-09-19 11:42:43 +02:00
Mike Kaplinskiy 949d74b516 Make it compile on more stringent compilers. 2014-09-17 13:27:44 -04:00
Mike Kaplinskiy f87a719d66 Fix exhaustion code when using multiple sockets. 2014-09-17 13:06:05 -04:00
Mike Kaplinskiy 8099dbd9e2 Don't spin if we exhaust the async worker pool. 2014-09-17 13:06:05 -04:00
Unbit 68bc194624 ensure PSGI response headers are in the right format [2] 2014-09-15 06:47:22 +02:00
Unbit 5bc5b7e01f ensure PSGI response headers are in the right format 2014-09-15 06:38:59 +02:00
unbit d37a1d3615 Merge pull request #698 from xrmx/debarchs
Fix forkptyrouter plugin compilation on Hurd
2014-09-12 10:14:02 +02:00
Roberto De Ioris 50e7b84fb5 uwsgi-2.1 merged to master 2014-09-12 06:47:41 +02:00
xiaost 73c3e971e6 python: add spooler_pids api for multi-spooler
the old `spooler_pid` api only returns the first spooler pid
2014-09-11 23:34:13 +08:00
Unbit 59a999af7b fix multiple python mountpoints with multiple threads in cow mode 2014-08-26 07:11:21 +02:00
Unbit e45f710694 fix multiple python mountpoints with multiple threads in cow mode 2014-08-26 07:10:27 +02:00
Martin Mlynář 3cfa743cb5 Update rados.c
According to http://ceph.com/docs/master/rados/api/librados/ rados_write Returns: 0 on success, negative error code on failure. When using <= comparsion, PUT method always ends with ISE 500.
2014-08-24 20:10:28 +02:00
Riccardo Magliocchetti e04e19aca4 Fix forkptyrouter plugin compilation on Hurd
While at it add missing linkage to libutil on other platforms
and fix compilation on DragonFlyBSD

Possibly Fix #694
2014-08-20 16:35:29 +02:00
Mike Kaplinskiy 1a4f333912 Allow --async 1 (i.e. sync mode, but with a different loop engine) 2014-08-17 13:13:17 -04:00
unbit 7fbc4013ca Merge pull request #679 from xrmx/logger
logfile: add support for filesize based rotation
2014-08-17 12:06:38 +02:00
Riccardo Magliocchetti 0324e5965c logfile: add support for filesize based rotation
Extends the logfile plugin sntax to accept a key value string.
Supported values are:
- logfile, the actual file name of the log file (mandatory)
- backupname, the file name of the rotated log
- maxsize, the size in bytes that triggers rotation

maxsize is mandatory if you want rotation, if you omit backupname the logfile with a
timestamp appended would be used as file name.

Example:

logger = staticlogger file:logfile=%dstatic.log,backupname=%dstatic.log.old,maxsize=1500
log-route = staticlogger app: -1|req: -1

will create a file based logger called static logger that would log
all the static requests to a file called static.log, which would be
rotated each 1500 bytes to a file named static.log.old

Fixes #542
2014-08-17 11:50:34 +02:00
Riccardo Magliocchetti 89bdb35ebc plugins/rpc: cleanup duplicated code
Introduce a couple of helpers to reduce duplicated code.

Before:
   text	   data	    bss	    dec	    hex	filename
   9742	    180	      0	   9922	   26c2	plugins/rpc/rpc_plugin.o

After:
   text	   data	    bss	    dec	    hex	filename
   9230	    180	      0	   9410	   24c2	plugins/rpc/rpc_plugin.o

My compiler inlines so uwsgi_rpc_get_remote it does make difference
in practice still it makes the code prettier.
2014-08-16 18:54:04 +02:00
Riccardo Magliocchetti b94727ef26 plugins/rpc: fix a couple of memory leaks
Always free response, in the worst case we are freeing NULL which
is a NOP.
Reported by Coverity as CID #1231246, #1231245
2014-08-16 18:53:42 +02:00
Riccardo Magliocchetti 4818a5d386 plugins/rpc: fix a couple of memory leaks
Always free response, in the worst case we are freeing NULL which
is a NOP.
Reported by Coverity as CID #1231246, #1231245
2014-08-16 16:52:59 +02:00
Roberto De Ioris 69034d2774 fixed mono on osx 2014-08-15 06:06:36 +02:00
Ventero 08e1cf211c Fix symbol lookup error in the Mono plugin on OS X.
On OS X, mono libraries have to link against the Foundation framework.
2014-08-14 21:35:39 +02:00
Unbit c6d90f3c42 fixed #669 2014-08-12 13:11:54 +02:00