Navigation Menu

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

net: SocketHandler logs peer id for close and disconnect #17251

Merged
merged 1 commit into from Oct 25, 2019

Conversation

Sjors
Copy link
Member

@Sjors Sjors commented Oct 25, 2019

When combined with -logips this makes it easier to diagnose disconnects.

To test on macOS, find a connection you want to disrupt:

lsof -nP -iTCP:8333 -sTCP:ESTABLISHED

To shut it down gracefully you can use tcpkill or this Python script: https://github.com/google/tcp_killer

The log should say:

2019-10-25T13:26:55Z socket closed for peer=1
2019-10-25T13:26:55Z disconnecting peer=1
2019-10-25T13:26:55Z Cleared nodestate for peer=1

To shut it down ungracefully I made a patch to the above script, adding a -force argument. Careful, this may result in data corruption. Then the log should say:

2019-10-25T13:39:57Z socket select error Bad file descriptor (9)
2019-10-25T13:39:57Z socket recv error for peer=0: Bad file descriptor (9)
2019-10-25T13:39:57Z disconnecting peer=0
2019-10-25T13:39:57Z Socket close failed: 35. Error: Bad file descriptor (9)
2019-10-25T13:39:57Z Cleared nodestate for peer=0

@fanquake fanquake added the P2P label Oct 25, 2019
@laanwj
Copy link
Member

laanwj commented Oct 25, 2019

ACK b62013c

@maflcko
Copy link
Member

maflcko commented Oct 25, 2019

This is already printed in the very next line

@Sjors
Copy link
Member Author

Sjors commented Oct 25, 2019

@MarcoFalke true. It's not very grep-friendly though, and many other log messages do include peer=N. And I also mistook the error code for the node id.

@emilengler
Copy link
Contributor

Don't know if it's a thing but why isn't the IP being displayed as well?

@Sjors
Copy link
Member Author

Sjors commented Oct 25, 2019

@emilengler putting IP addresses in the log was disabled by default in #3764 for privacy reasons

@Sjors
Copy link
Member Author

Sjors commented Oct 25, 2019

@TheBlueMatt suggested making the error message debug=net only

@maflcko
Copy link
Member

maflcko commented Oct 25, 2019

unsigned ACK 04dbdd6

@TheBlueMatt
Copy link
Contributor

unsigned ACK 04dbdd6 LGTM!

@theuni
Copy link
Member

theuni commented Oct 25, 2019

I've definitely hacked this in locally before.

unsigned ACK 04dbdd6.

fanquake added a commit that referenced this pull request Oct 25, 2019
04dbdd6 [net] SocketHandler: log peer id for close and disconnect (Sjors Provoost)

Pull request description:

  When combined with `-logips` this makes it easier to diagnose disconnects.

  To test on macOS, find a connection you want to disrupt:

  ```
  lsof -nP -iTCP:8333 -sTCP:ESTABLISHED
  ```

  To shut it down gracefully you can use tcpkill or this Python script: https://github.com/google/tcp_killer

  The log should say:

  ```
  2019-10-25T13:26:55Z socket closed for peer=1
  2019-10-25T13:26:55Z disconnecting peer=1
  2019-10-25T13:26:55Z Cleared nodestate for peer=1
  ```

  To shut it down ungracefully I made a patch to the above script, adding a `-force` argument. _Careful, this may result in data corruption_. Then the log should say:

  ```
  2019-10-25T13:39:57Z socket select error Bad file descriptor (9)
  2019-10-25T13:39:57Z socket recv error for peer=0: Bad file descriptor (9)
  2019-10-25T13:39:57Z disconnecting peer=0
  2019-10-25T13:39:57Z Socket close failed: 35. Error: Bad file descriptor (9)
  2019-10-25T13:39:57Z Cleared nodestate for peer=0
  ```

ACKs for top commit:
  MarcoFalke:
    unsigned ACK 04dbdd6
  TheBlueMatt:
    unsigned ACK 04dbdd6 LGTM!
  theuni:
    unsigned ACK 04dbdd6.

Tree-SHA512: 415313908484f97ffe11a48b4ed6afab3ab0be660c788adb9ad975f88b69aa1cfd5ccbe5859350cdf19ef8fde191fd530fb22cef34e70638defdc9f3d761c71d
@fanquake fanquake merged commit 04dbdd6 into bitcoin:master Oct 25, 2019
@Sjors Sjors deleted the 2019/10/net-socket-peer branch October 25, 2019 19:09
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 14, 2020
Summary:
04dbdd613fe5c0a742de915e07553614cd4cbf46 [net] SocketHandler: log peer id for close and disconnect (Sjors Provoost)

Pull request description:

  When combined with `-logips` this makes it easier to diagnose disconnects.

  To test on macOS, find a connection you want to disrupt:

  ```
  lsof -nP -iTCP:8333 -sTCP:ESTABLISHED
  ```

  To shut it down gracefully you can use tcpkill or this Python script: https://github.com/google/tcp_killer

  The log should say:

  ```
  2019-10-25T13:26:55Z socket closed for peer=1
  2019-10-25T13:26:55Z disconnecting peer=1
  2019-10-25T13:26:55Z Cleared nodestate for peer=1
  ```

  To shut it down ungracefully I made a patch to the above script, adding a `-force` argument. _Careful, this may result in data corruption_. Then the log should say:

  ```
  2019-10-25T13:39:57Z socket select error Bad file descriptor (9)
  2019-10-25T13:39:57Z socket recv error for peer=0: Bad file descriptor (9)
  2019-10-25T13:39:57Z disconnecting peer=0
  2019-10-25T13:39:57Z Socket close failed: 35. Error: Bad file descriptor (9)
  2019-10-25T13:39:57Z Cleared nodestate for peer=0
  ```

Backport of Core [[bitcoin/bitcoin#17251 | PR17251]]

Test Plan: `ninja check check-functional`

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7921
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants