Best way to prevent "mux_client_request_session: read from master failed: Broken pipe" ssh errors

Viewed 9951

I've got a perl script that creates an ssh tunnel and sets up a Perl DBI connection across it to query a database on a remote host:

1 my $ssh = Net::OpenSSH->new('me@host.com');
2 $pid = $ssh->spawn({ssh_opts => '-L 127.0.0.1:12345:127.0.0.1:3306'}, 'sleep 3');

3 return DBI->connect($dsn, $db_user, $db_pass);

This works about 80 to 90% of the time but the rest of the time I get this error when trying to connect to the database:

mux_client_request_session: read from master failed: Broken pipe

In the process of troubleshooting this, I noticed if I sleep the program very briefly after line 2 with usleep (10000), it works 100% of the time. I'm not sure why this is but I'm curious know and how I can properly fix the issue.

Thanks.

1 Answers
Related