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

File handle writes on broken connection results in out-of-memory #17

Open
jozef opened this issue Oct 1, 2020 · 4 comments
Open

File handle writes on broken connection results in out-of-memory #17

jozef opened this issue Oct 1, 2020 · 4 comments

Comments

@jozef
Copy link

jozef commented Oct 1, 2020

Hello,

one-liner that will allocate gigabytes of memory:

perl -MNet::SFTP::Foreign -lE 'use Net::SFTP::Foreign::Constants qw(:flags); my $sftp = Net::SFTP::Foreign->new("localhost"); my $fh = $sftp->open("/tmp/test-pls-delete", SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC) or die $sftp->error; print $fh "x"x1000; kill('HUP',$sftp->{pid}); for (1..100_000) { print $fh "x"x1000 or die "print failed" };'

or pretty formatted:

#!/usr/bin/env perl

use Net::SFTP::Foreign;
use Net::SFTP::Foreign::Constants qw(:flags);

my $sftp = Net::SFTP::Foreign->new("localhost");
my $fh =
    $sftp->open( "/tmp/test-pls-delete",
    SSH2_FXF_WRITE | SSH2_FXF_CREAT | SSH2_FXF_TRUNC )
    or die $sftp->error;
print $fh "x" x 1000;

# loosing ssh process results in memory over allocation somewhere in write()
kill( 'HUP', $sftp->{pid} );

for ( 1 .. 100_000 ) {
    print $fh "x" x 1000 or die "print failed";
}

kill( 'HUP', $sftp->{pid} ); line triggers lost-connection conditions, without it script would create ~100MB file in /tmp.

Quick work-around is to set autodie=1.

Would be good if write()/print() functions will return fail in case of broken connection and at the same time not overfill message buffers.

Best regards
Jozef

@salva
Copy link
Owner

salva commented Oct 1, 2020

Hi, thank you for the report!

I have just released version 1.92_03 with a fix for this issue: https://metacpan.org/release/SALVA/Net-SFTP-Foreign-1.92_03

@salva
Copy link
Owner

salva commented Oct 15, 2020

Hi!

Have you been able to test the new version?

@jozef
Copy link
Author

jozef commented Oct 16, 2020

Hello, thank you for the quick fix! I've tested locally right away → works good. I'll be able to test on our staging servers following week with real traffic.

@jozef
Copy link
Author

jozef commented Oct 27, 2020

Works good, thank you!

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

No branches or pull requests

2 participants