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

Fix sendinput hanging forever when connection is blocked #207

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

kdisneur
Copy link
Contributor

@kdisneur kdisneur commented Dec 13, 2024

Hello

We have an issue since we bumped from v1.3.2 to v1.3.3 in our unit tests.

We have a test where we send a command to a device and expect it to fail with a timeout (we try to simulate a device experiencing a connection issue and not responding anymore). The test was working before and now hang infinitely.

I reproduced the test case in v1.3.2 where we send the command show running-config and Scrapligo can only read back a part of the output.

Here the test case executed against commit v1.3.2 (commit: a6c4329)

git checkout v1.3.2_testcase
go test -count 1 ./channel -run TestScrapligoSendCommandErrorTimeout
ok      github.com/scrapli/scrapligo/channel    0.006s

Here the same test case executed against commit v1.3.3 (commit: 7ea22c0)

git checkout v1.3.3_testcase
go test -count 1 ./channel -run TestScrapligoSendCommandErrorTimeout
^Csignal: interrupt
FAIL    github.com/scrapli/scrapligo/channel    175.238s
FAIL

I think this is caused by this call to r := <-cr because it doesn't take into account the timeout of the context.
I don't know / understand the full implication of my proposal but this pull-request would fix our specific use case:

git checkout v1.3.3_fix
go test -count 1 ./channel -run TestScrapligoSendCommandErrorTimeout
ok      github.com/scrapli/scrapligo/channel    0.006s

@carlmontanari
Copy link
Contributor

👋 hey, happy friday! will try to check it out later today or this weekend a bit more and get it merged, thanks for the pr!

@carlmontanari
Copy link
Contributor

👋 hey @kdisneur and @moubella thanks again for opening this! I just pushed a little change that I think should sort ya out -- the test you added (thank you very very much for that!) passes with m changes so should be good I think. tl;dr the recent context/timeout fixes missed (or I was lazy?) passing context to the readUntilF so that led to a case where reading until inputs could block forever, whoops :) holler if this looks good/sorts your issue and we'll get it merged!

@kdisneur
Copy link
Contributor Author

Hello

Thanks for the quick feedback and your improvement. We can confirm you change still makes the test pass on our side. 👍

@carlmontanari
Copy link
Contributor

awesome! thanks for confirming and thanks for the work on this! 🚀

@carlmontanari carlmontanari merged commit 69f1f0b into scrapli:main Dec 16, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants