Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPC leaks connections (when internally using PubSubSession) #275

Closed
gnunicorn opened this issue Jun 5, 2018 · 1 comment · Fixed by #277
Closed

IPC leaks connections (when internally using PubSubSession) #275

gnunicorn opened this issue Jun 5, 2018 · 1 comment · Fixed by #277

Comments

@gnunicorn
Copy link

gnunicorn commented Jun 5, 2018

Heyah,

investigating a leak in IPC connections in Parity I was able to pin-point the location to the way that IPC-Server and PubSubSession are interacting leading to an internal circle of never ending futures. Which in turn means we are keeping those connections around even after they've terminated, keep the socket open and - ultimatily - leak those connections as well as memory, causing Parity to be oom-killed (at least I suspect this error to be the cause of that error. Can't rule out there might be another leak).

I've commited a short example triggering that behaviour, together with some code comments of the cause (IMHO) in this branch.

To reproduce this bug, check out the leaking-ipc-connections-example branch, cd into ipc and run

RUST_LOG=ipc=trace cargo run --example with-pubsubsession

Now have something connect to the open socket /tmp/json-ipc-test.ipc and immediately close again or die, like so:

#!/bin/sh -e
for i in `seq 0 1000`
do
    echo $i
    nc localhost 30303 </dev/null >/dev/null &
    pid=$!
    sleep 0.1
    kill $pid
done;

You'll see a bunch of messages appear in the example looking something like

    Finished dev [unoptimized + debuginfo] target(s) in 4.23 secs
     Running `/home/ben/dev/parity/jsonrpc/target/debug/examples/with-pubsubsession`
TRACE 2018-06-05T10:33:41Z: jsonrpc_ipc_server::server: Accepted incoming IPC connection: 1
TRACE 2018-06-05T10:33:41Z: with_pubsubsession: ext
TRACE 2018-06-05T10:33:41Z: jsonrpc_ipc_server::server: Accepted incoming IPC connection: 2
TRACE 2018-06-05T10:33:41Z: with_pubsubsession: ext
TRACE 2018-06-05T10:33:41Z: jsonrpc_ipc_server::server: Accepted incoming IPC connection: 3
TRACE 2018-06-05T10:33:41Z: with_pubsubsession: ext

Notice how the closing message Peer: service finished is absent -- connections aren't dropped even though the peer is gone.

You can also watch it grow the open file handlers with lsof (e.g. while true; do echo "`date +%s` : `lsof -c with-pubs | wc -l`"; sleep 5; done)

debris added a commit that referenced this issue Jun 6, 2018
@debris debris mentioned this issue Jun 6, 2018
@dvdplm
Copy link
Contributor

dvdplm commented Jun 6, 2018

For posterity, here's a repeat-script that worked for me (thanks @debris):

#!/bin/sh -e
for i in `seq 0 1000`
do
    echo $i
    nc -U /tmp/json-ipc-test.ipc </dev/null >/dev/null &
    pid=$!
    sleep 0.1
    kill $pid
done;

(also, om macos, brew uninstall netcat if you have it)

debris added a commit that referenced this issue Jun 12, 2018
* fixed ipc connection leak, closes #275

* fixed indentation

* fixed broken pipe issue in tests

* empirical tests fixes

* fix tests

* fix tests

* fix tests

* move ipc start_signal.send after the incoming.for_each

* log ipc traces on travis

* keep writer in memory as long as possible

* select_with_weak

* remove redundant thread::sleep

* test session end

* fixed race condition in test_session_end
debris added a commit that referenced this issue Jun 12, 2018
* fixed ipc connection leak, closes #275

* fixed indentation

* fixed broken pipe issue in tests

* empirical tests fixes

* fix tests

* fix tests

* fix tests

* move ipc start_signal.send after the incoming.for_each

* log ipc traces on travis

* keep writer in memory as long as possible

* select_with_weak

* remove redundant thread::sleep

* test session end

* fixed race condition in test_session_end
debris added a commit that referenced this issue Jun 12, 2018
* fixed ipc connection leak, closes #275

* fixed indentation

* fixed broken pipe issue in tests

* empirical tests fixes

* fix tests

* fix tests

* fix tests

* move ipc start_signal.send after the incoming.for_each

* log ipc traces on travis

* keep writer in memory as long as possible

* select_with_weak

* remove redundant thread::sleep

* test session end

* fixed race condition in test_session_end
debris added a commit that referenced this issue Jun 18, 2018
* fixed ipc connection leak, closes #275

* fixed indentation

* fixed broken pipe issue in tests

* empirical tests fixes

* fix tests

* fix tests

* fix tests

* move ipc start_signal.send after the incoming.for_each

* log ipc traces on travis

* keep writer in memory as long as possible

* select_with_weak

* remove redundant thread::sleep

* test session end

* fixed race condition in test_session_end
ascjones pushed a commit that referenced this issue Jun 18, 2018
* fixed ipc connection leak, closes #275

* fixed indentation

* fixed broken pipe issue in tests

* empirical tests fixes

* fix tests

* fix tests

* fix tests

* move ipc start_signal.send after the incoming.for_each

* log ipc traces on travis

* keep writer in memory as long as possible

* select_with_weak

* remove redundant thread::sleep

* test session end

* fixed race condition in test_session_end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants