{"action":"created","issue":{"url":"https://api.github.com/repos/unbit/uwsgi/issues/990","labels_url":"https://api.github.com/repos/unbit/uwsgi/issues/990/labels{/name}","comments_url":"https://api.github.com/repos/unbit/uwsgi/issues/990/comments","events_url":"https://api.github.com/repos/unbit/uwsgi/issues/990/events","html_url":"https://github.com/unbit/uwsgi/issues/990","id":97909440,"number":990,"title":"atexit() not called when terminating mules (psgi)","user":{"login":"aldem","id":754722,"avatar_url":"https://avatars.githubusercontent.com/u/754722?v=3","gravatar_id":"","url":"https://api.github.com/users/aldem","html_url":"https://github.com/aldem","followers_url":"https://api.github.com/users/aldem/followers","following_url":"https://api.github.com/users/aldem/following{/other_user}","gists_url":"https://api.github.com/users/aldem/gists{/gist_id}","starred_url":"https://api.github.com/users/aldem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldem/subscriptions","organizations_url":"https://api.github.com/users/aldem/orgs","repos_url":"https://api.github.com/users/aldem/repos","events_url":"https://api.github.com/users/aldem/events{/privacy}","received_events_url":"https://api.github.com/users/aldem/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-29T10:40:29Z","updated_at":"2015-07-30T18:30:20Z","closed_at":null,"body":"Hi,\r\n\r\nNot sure if this is a bug or intended behavior, but, unlike as for workers, atexit() hook is not called when mule is terminated, though postfork() is called as usual (tested on 2.0.11.1)"},"comment":{"url":"https://api.github.com/repos/unbit/uwsgi/issues/comments/126425942","html_url":"https://github.com/unbit/uwsgi/issues/990#issuecomment-126425942","issue_url":"https://api.github.com/repos/unbit/uwsgi/issues/990","id":126425942,"user":{"login":"aldem","id":754722,"avatar_url":"https://avatars.githubusercontent.com/u/754722?v=3","gravatar_id":"","url":"https://api.github.com/users/aldem","html_url":"https://github.com/aldem","followers_url":"https://api.github.com/users/aldem/followers","following_url":"https://api.github.com/users/aldem/following{/other_user}","gists_url":"https://api.github.com/users/aldem/gists{/gist_id}","starred_url":"https://api.github.com/users/aldem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldem/subscriptions","organizations_url":"https://api.github.com/users/aldem/orgs","repos_url":"https://api.github.com/users/aldem/repos","events_url":"https://api.github.com/users/aldem/events{/privacy}","received_events_url":"https://api.github.com/users/aldem/received_events","type":"User","site_admin":false},"created_at":"2015-07-30T18:30:20Z","updated_at":"2015-07-30T18:30:20Z","body":"Config is as simple as it can be: uwsgi --http-socket :9090 -L -M --mule --psgi uwsgi-dummy.pl\r\n\r\nBut after some investigation, it seems that I found how (but not why) this happens - I have $SIG{INT} handler set in postfork(), which prevents execution of atexit() in mule (though it does not prevent atexit() in worker).\r\n\r\nWhat is a bit puzzling, though, is that this sigint handler is not called at all (but I can live with that). My sample code:\r\n\r\n```perl\r\nuse strict;\r\nuse warnings;\r\n\r\nuwsgi::log(\"[$$] Initializing\\n\");\r\n\r\nuwsgi::postfork(sub {\r\n    uwsgi::log(\"[$$]: postfork()\\n\");\r\n    $SIG{INT} = sub {\r\n        uwsgi::log(\"[$$] SIGINT received\\n\");\r\n    };\r\n});\r\n\r\nuwsgi::atexit(sub {\r\n    uwsgi::log(\"[$$]: atexit()\\n\");\r\n});\r\n\r\nmy $app = sub {\r\n    return [200, [ \"Content-Type\" => 'text/plain' ], [\"There is nothing to see here, sorry\\n\"]];\r\n};\r\n```\r\n\r\nAnd the output when killing:\r\n```\r\n...\r\n[5298] Initializing\r\nPSGI app 0 (uwsgi-d.pl) loaded in 0 seconds at 0x1804ab0 (interpreter 0x15ca5d0)\r\n*** uWSGI is running in multiple interpreter mode ***\r\nspawned uWSGI master process (pid: 5298)\r\nspawned uWSGI worker 1 (pid: 5299, cores: 1)\r\n[5299]: postfork()\r\nspawned uWSGI mule 1 (pid: 5300)\r\n[5300]: postfork()\r\n^CSIGINT/SIGQUIT received...killing workers...\r\n[5299]: atexit()\r\nworker 1 buried after 1 seconds\r\ngoodbye to uWSGI.\r\n```\r\n\r\nNo output from signal handler and from atexit() in mule. Tried this on CentOS 6 (perl 5.8) and CentOS 7 (perl 5.16), uwsgi 2.0.11.1 - same result.\r\n"}}