featureprofiles icon indicating copy to clipboard operation
featureprofiles copied to clipboard

add cancellable context in ssh CLI

Open LiamWalsh98 opened this issue 9 months ago • 4 comments

When using the RunCommand function, there is a case where if an SSH connection is stopped from the server side without closing the connection, the program calling it will halt and be unable to resume. This may occur when a router is restarted, after which the severed ssh session will not be reestablished.

To illustrate, this line will cause deadlock

cliClient.RunCommand(context.Background(), "run killall -STOP sshd")

note: this will also block incoming ssh until killall -CONT sshd is executed. For testing, try instead run killall -STOP sshd; sleep 10s; killall -CONT sshd

with the proposed changes, it can be handled using a context with a timeout/deadline (or otherwise cancelled)

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
cliClient.RunCommand(ctx, "run killall -STOP sshd")

Have also added the sshConfig timeout to DialCLI's ClientConfig.

LiamWalsh98 avatar May 08 '24 18:05 LiamWalsh98

Pull Request Functional Test Report for #2971 / 4b8161eda812bd084a6ffa4ed53474170dc9c7cd

No tests identified for validation.

Help

OpenConfigBot avatar May 08 '24 18:05 OpenConfigBot

Pull Request Test Coverage Report for Build 9006523799

Details

  • 18 of 25 (72.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 55.973%

Changes Missing Coverage Covered Lines Changed/Added Lines %
topologies/binding/binding.go 0 1 0.0%
topologies/binding/cli.go 18 24 75.0%
<!-- Total: 18 25
Totals Coverage Status
Change from base Build 9004753373: 0.1%
Covered Lines: 1996
Relevant Lines: 3566

💛 - Coveralls

coveralls avatar May 08 '24 18:05 coveralls

Hi @dplore , could someone take a look at this PR

singh-prem avatar Jul 24 '24 14:07 singh-prem

Hi @ram-mac please review, thank you.

dplore avatar Jul 24 '24 17:07 dplore