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

client: fix Do hangs when configure host client fails #1514

Merged
merged 1 commit into from
Mar 11, 2023
Merged

client: fix Do hangs when configure host client fails #1514

merged 1 commit into from
Mar 11, 2023

Conversation

alexandear
Copy link
Contributor

@alexandear alexandear commented Mar 8, 2023

This PR fixes a situation when the second call to client.Do hangs when usingc.ConfigureClient(hc) on the first call client.Do.

Without the fix, TestClientConfigureClientFailed get stuck because mutex c.mLock is never unlocked. And timed out with the stack trace:

go test -timeout 30s -run ^TestClientConfigureClientFailed$ github.com/valyala/fasthttp -count=1 -v -race

=== RUN   TestClientConfigureClientFailed
=== PAUSE TestClientConfigureClientFailed
=== CONT  TestClientConfigureClientFailed
panic: test timed out after 30s
running tests:
	TestClientConfigureClientFailed (30s)

goroutine 33 [running]:
testing.(*M).startAlarm.func1()
	/usr/local/Cellar/go/1.20.1/libexec/src/testing/testing.go:2241 +0x219
created by time.goFunc
	/usr/local/Cellar/go/1.20.1/libexec/src/time/sleep.go:176 +0x48

goroutine 1 [chan receive]:
testing.tRunner.func1()
	/usr/local/Cellar/go/1.20.1/libexec/src/testing/testing.go:1542 +0x8eb
testing.tRunner(0xc000083040, 0xc000095b48)
	/usr/local/Cellar/go/1.20.1/libexec/src/testing/testing.go:1582 +0x255
testing.runTests(0xc0000bcbe0?, {0x1c4d020, 0x1b5, 0x1b5}, {0x1c?, 0x1e?, 0x1c51620?})
	/usr/local/Cellar/go/1.20.1/libexec/src/testing/testing.go:2034 +0x87d
testing.(*M).Run(0xc0000bcbe0)
	/usr/local/Cellar/go/1.20.1/libexec/src/testing/testing.go:1906 +0xb45
main.main()
	_testmain.go:1141 +0x2ea

goroutine 18 [sleep]:
time.Sleep(0x12a05f200)
	/usr/local/Cellar/go/1.20.1/libexec/src/runtime/time.go:195 +0x135
github.com/valyala/fasthttp.(*FS).initRequestHandler.func1()
	/Users/redko.o/src/github.com/valyala/fasthttp/fs.go:478 +0x1e6
created by github.com/valyala/fasthttp.(*FS).initRequestHandler
	/Users/redko.o/src/github.com/valyala/fasthttp/fs.go:455 +0x96f

goroutine 19 [sleep]:
time.Sleep(0x12a05f200)
	/usr/local/Cellar/go/1.20.1/libexec/src/runtime/time.go:195 +0x135
github.com/valyala/fasthttp.(*FS).initRequestHandler.func1()
	/Users/redko.o/src/github.com/valyala/fasthttp/fs.go:478 +0x1e6
created by github.com/valyala/fasthttp.(*FS).initRequestHandler
	/Users/redko.o/src/github.com/valyala/fasthttp/fs.go:455 +0x96f

goroutine 20 [sleep]:
time.Sleep(0x12a05f200)
	/usr/local/Cellar/go/1.20.1/libexec/src/runtime/time.go:195 +0x135
github.com/valyala/fasthttp.(*FS).initRequestHandler.func1()
	/Users/redko.o/src/github.com/valyala/fasthttp/fs.go:478 +0x1e6
created by github.com/valyala/fasthttp.(*FS).initRequestHandler
	/Users/redko.o/src/github.com/valyala/fasthttp/fs.go:455 +0x96f

goroutine 21 [sync.Mutex.Lock]:
sync.runtime_SemacquireMutex(0x1b9b6e8?, 0x4?, 0x10a58e0?)
	/usr/local/Cellar/go/1.20.1/libexec/src/runtime/sema.go:77 +0x26
sync.(*Mutex).lockSlow(0xc0000d2520)
	/usr/local/Cellar/go/1.20.1/libexec/src/sync/mutex.go:171 +0x213
sync.(*Mutex).Lock(0xc0000d2520)
	/usr/local/Cellar/go/1.20.1/libexec/src/sync/mutex.go:90 +0x65
github.com/valyala/fasthttp.(*Client).Do(0xc0000d2480, 0xc0000a8e00, 0x17f540c?)
	/Users/redko.o/src/github.com/valyala/fasthttp/client.go:487 +0x265
github.com/valyala/fasthttp.TestClientConfigureClientFailed(0xc0000831e0)
	/Users/redko.o/src/github.com/valyala/fasthttp/client_test.go:2755 +0x365
testing.tRunner(0xc0000831e0, 0x1837ed8)
	/usr/local/Cellar/go/1.20.1/libexec/src/testing/testing.go:1576 +0x217
created by testing.(*T).Run
	/usr/local/Cellar/go/1.20.1/libexec/src/testing/testing.go:1629 +0x806
FAIL	github.com/valyala/fasthttp	30.396s

@erikdubbelboer erikdubbelboer merged commit 7846101 into valyala:master Mar 11, 2023
@erikdubbelboer
Copy link
Collaborator

Thanks!

@alexandear alexandear deleted the fix-missing-client-unlock branch March 11, 2023 17:15
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 this pull request may close these issues.

2 participants