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

Too many CLOSE_WAIT after access via http api #6295

Closed
suutaku opened this issue May 5, 2019 · 11 comments · Fixed by #6311
Closed

Too many CLOSE_WAIT after access via http api #6295

suutaku opened this issue May 5, 2019 · 11 comments · Fixed by #6311
Assignees
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@suutaku
Copy link

suutaku commented May 5, 2019

Version information:

JohnSuus-MacBook-Pro-4:build john$ ipfs version --all go-ipfs version: 0.4.21-dev-7e9eb72bf Repo version: 7 System version: amd64/darwin Golang version: go1.12.4

Type:

Bug

Description:

Running ipfs daemon on Mac OS X 10.13.6.
Access 127.0.0.1:5001/api/v0/xxxxxx once per second. after about 10 minute, running
sudo losf -nP -iTCP:5001
I got 300+ TCP CLOSE_WAIT status.
It's some kind of FD leaks?

I had follow @Stebalien 's suggestion to modify code
go-ipfs/core/corehttp/corehttp.go

by added
server.SetKeepAlivesEnabled(false)
after

server := &http.Server{ 
 	Handler: handler, 
 } 

but it finally invalid.

and I also set a nginx reverse proxy out in front, the number of CLOSE_WAIT was keep increasing.

can you take a look agin?
now my server is down due this issue....

@suutaku
Copy link
Author

suutaku commented May 6, 2019

update

I found CLOSE_WAIT only happens on invalid access. for example, client side reach the timeout, terminate the connection and have not receive response from daemon.
I tested command of IPFS HTTP API.
by add progress=true flag to /pin/add command, no CLOSE_WAIT happen even the hash is invalid.
but commands like pin/rm have no flag like progress , so it still CLOSE_WAIT when client reach the timeout.

@Stebalien
Copy link
Member

Wait, are you seeing TIME_WAIT or CLOSE_WAIT?

@Stebalien Stebalien added the kind/bug A bug in existing code (including security flaws) label May 6, 2019
@suutaku
Copy link
Author

suutaku commented May 7, 2019

Wait, are you seeing TIME_WAIT or CLOSE_WAIT?

I'm sorry! typing miss. It's CLOSE_WAIT !!!!!!!

@suutaku
Copy link
Author

suutaku commented May 8, 2019

@Stebalien
after check the source code. if client reach the timeout, IPFS hang on serverHandler{c.server}.ServeHTTP(w, w.req) at net/http/server.go:1884 (I added some debug logs, maybe that code is not line 1884).
I think is IPFS handleFunc's bug?

Update

I add a ticker to check if connection was CLOSE_WAIT status close it. but only close connection, serverHandler{c.server}.ServeHTTP(w, w.req) still not return.

@Stebalien
Copy link
Member

Stebalien commented May 8, 2019

Could you run curl http://127.0.0.1:5001/debug/pprof/goroutine?debug=2 > goroutines and upload the result? That'll tell me where it's getting stuck.

@suutaku
Copy link
Author

suutaku commented May 9, 2019

http://www.cotnetwork.com/goroutines
ipfs version 0.4.21-dev

@Stebalien
Copy link
Member

Were you reproducing the issue when you ran curl http://127.0.0.1:5001/debug/pprof/goroutine?debug=2 > goroutines? I'm not seeing anything stuck in ServeHTTP.

@suutaku
Copy link
Author

suutaku commented May 9, 2019

client (curl) was quit. but ServeHTTP for client request still running (for a long time). At this time, TCP was CLOSE_WAIT on server side.

@Stebalien
Copy link
Member

I see. So the bug is specifically with ipfs pin add and ipfs pin rm. It looks like we aren't feeding the context all the way through so we're not completely canceling the operation.

Stebalien added a commit that referenced this issue May 9, 2019
We do this _just_ to make the error nicer but it's really slow. Additionally, we
do it while holding the pin lock, blocking all other pin operations.

fixes #6295

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
@ghost ghost assigned Stebalien May 9, 2019
@ghost ghost added the status/in-progress In progress label May 9, 2019
@suutaku
Copy link
Author

suutaku commented May 9, 2019

thank you. I'm going to test it.

@suutaku
Copy link
Author

suutaku commented May 9, 2019

problem solved.
thank you agin!

@suutaku suutaku closed this as completed May 9, 2019
@ghost ghost removed the status/in-progress In progress label May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants