Comments (8)
Actually, after some extensive experiments and use, SIG_IGN seems to fix the issue.
Here is the PR:
#6764
from mitmproxy.
Can you please verify if that still reproduces with the latest mitmproxy release, and also provide the full traceback including the SIGPIPE error message?
from mitmproxy.
I upgraded to the latest build and it still repros.
The offending line is still the same. Just the line numbers are different.
Would it make sense to put a lock for a fix?
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
mitmproxy version info:
Mitmproxy: 10.2.4
Python: 3.10.11
OpenSSL: OpenSSL 3.2.1 30 Jan 2024
Platform: macOS-14.4-arm64-arm-64bit
Here is how we are capturing the SIGPIPE signal
###Received signal: 13, printing stack trac
def signal_handler(signal_received, frame):
logger.error(f"###Received signal: {signal_received}, printing stack trace:")
traceback.print_stack(frame)
def hookup_signal_handler():
signal.signal(signal.SIGPIPE, signal_handler)
from mitmproxy.
After looking at this for a bit -- I'm all but an expert on unix signals --, it sounds like mitmproxy should run signal(SIGPIPE, SIG_IGN)
on startup. Can you confirm that this would fix the issue for you (for testing you can run that from an addon)? If yes, can you please send a PR that add this call here? Thanks!
from mitmproxy.
You mean like this, right?
signal.signal(signal.SIGINT, _sigint)
signal.signal(signal.SIGTERM, _sigterm)
signal.signal(signal.SIGPIPE, SIG_IGN) <-- added
This just ignores SIGPIPE signal, right? Would it make the bad connection stay bad?
How is it different from the signal handler that I had earlier?
How about adding this to server.py? In the signal_handler, we close the bad connection.
This seems to work better in our internal testing.
# workaround for https://bugs.python.org/issue40124 / https://bugs.python.org/issue29930
self._drain_lock = asyncio.Lock()
signal.signal(signal.SIGPIPE, self.signal_handler)
def signal_handler(self, signal_received, frame):
self.log(f"###Received signal1: {signal_received}, printing stack trace:", logging.ERROR)
traceback.print_stack(frame)
self.log("client kill connection")
writer = self.transports.pop(self.client).writer
assert writer
writer.close()
from mitmproxy.
This seems to work better in our internal testing.
Can you clarify by which metric this works better? The code you posted seems to work as well, but reassigning the signal handler on every write seems unnecessarily costly.
FYI If you run git diff > out.txt
and then paste the contents of out.txt here, we get a much nicer output that's easier to interpret due to filenames and line numbers. :)
from mitmproxy.
We added signal.signal(signal.SIGPIPE, SIG_IGN)
but that did not resolve the issue.
The symptoms on my machine:
- If you open Slack the next day, Slack is not able to connect
- Intermittently, some websites won't load up but after 30 seconds, it will automatically retry and connect.
from mitmproxy.
@hans-at-strac: To confirm, the patch posted by @changsin does definitely fix the issue, but just setting SIG_IGN doesn't?
We're seeing one error message here (SIGPIPE) and some particular networking issues. But I'd like to make sure that there also is causality between these two.
Can you send SIGUSR1 / SIGUSR2 to the mitmproxy process when this Slack issue occurs? Ideally on an otherwise silent network.
from mitmproxy.
Related Issues (20)
- Fixing AMF parsing HOT 5
- Questions about Copilot + Open Source Software Hierarchy HOT 1
- Standalone Binaries: linux-arm64 (aarch64) HOT 8
- mitmdump stdout never reaches parent process HOT 25
- Can't handle a connection without server or with timeout HOT 5
- Unexpected event type at TCPLayer.relay_messages: Expected DataReceived|ConnectionClosed|TcpMessageInjected, got Start({}) HOT 13
- Deprecation Warning for not_valid_after in certs.py
- different output from io.FlowReader and io.FlowWrite HOT 1
- ERR_CONNECTION_RESET on android emulator HOT 2
- Cannot type header filter expression alone in mitmweb but no problem with the terminal mitmproxy
- Request to add a "clear all" button to the web interface HOT 2
- 403 access forbidden for www.youtube.com
- (trapped) error reading bcrypt version HOT 1
- Mitmdump does not exit HOT 1
- WireGuard mode in mitmproxy where find client config file? How work with it? Any documentation? HOT 1
- mitmdump 8.1.1 installed via apt fails to start - No module named 'blinker._saferef' HOT 2
- when i exec master.shutdown() the port not be free
- ImportError: `GLIBC_2.33' not found HOT 5
- HTTP/2 protocol error: Invalid input ConnectionInputs.RECV_DATA HOT 5
- httpauth is not attached to replay request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mitmproxy.