Skip to content

Commit

Permalink
Setting SIG_IGN for SIGPIPE errors (mitmproxy#6764)
Browse files Browse the repository at this point in the history
* Setting SIG_IGN for SIGPIPE errors

    The issue was reported in mitmproxy#6744

    Problem description:
    When there is a sudden surge of requests, mitmproxy will hit SIGPIPE (broken pipe) errors because it was trying to write to a closed socket. The stacktrace is:
    File "asyncio/runners.py", line 44, in run
    File "asyncio/base_events.py", line 636, in run_until_complete
    File "asyncio/base_events.py", line 603, in run_forever
    File "asyncio/base_events.py", line 1909, in _run_once
    File "asyncio/events.py", line 80, in _run
    File "mitmproxy/proxy/server.py", line 294, in handle_connection
    File "mitmproxy/proxy/server.py", line 407, in server_event
    File "asyncio/streams.py", line 325, in write
    File "asyncio/selector_events.py", line 924, in write

    When this happens, the process terminates unless handled
    The fix will allow the process to continue to run.

* add changelog entry

* [autofix.ci] apply automated fixes

* Handling SIGPIPE only in non-Windows platforms

* [autofix.ci] apply automated fixes

* nit: make check platform-agnostic

---------

Co-authored-by: changsin <[email protected]>
Co-authored-by: Maximilian Hils <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Apr 3, 2024
1 parent ccf45a9 commit 8cf0cba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
([#6747](https://github.com/mitmproxy/mitmproxy/pull/6747), @jlaine)
* Fix a bug where async `client_connected` handlers would crash mitmproxy.
([#6749](https://github.com/mitmproxy/mitmproxy/pull/6749), @mhils)
* Add button to close flow details panel
* Add button to close flow details panel
([#6734](https://github.com/mitmproxy/mitmproxy/pull/6734), @lups2000)
* Ignore SIGPIPE signals when there is lots of traffic.
Socket errors are handled directly and do not require extra signals
that generate noise.
([#6764](https://github.com/mitmproxy/mitmproxy/pull/6764), @changsin)
* Add primitive websocket interception and modification
([#6766](https://github.com/mitmproxy/mitmproxy/pull/6766), @errorxyz)

Expand Down
4 changes: 4 additions & 0 deletions mitmproxy/tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def _sigterm(*_):
# but signal.signal just works fine for our purposes.
signal.signal(signal.SIGINT, _sigint)
signal.signal(signal.SIGTERM, _sigterm)
# to fix the issue mentioned https://github.com/mitmproxy/mitmproxy/issues/6744
# by setting SIGPIPE to SIG_IGN, the process will not terminate and continue to run
if hasattr(signal, "SIGPIPE"):
signal.signal(signal.SIGPIPE, signal.SIG_IGN)

await master.run()
return master
Expand Down

0 comments on commit 8cf0cba

Please sign in to comment.