Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Close socket when client sends EOF #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

michal-kazmierczak
Copy link

@michal-kazmierczak michal-kazmierczak commented Aug 21, 2019

As is:
When a client triggers EOF in server to close connection (in Ruby client ftp.close) the server doesn't handle this signal and forces the client to wait on read.

To be:
When EOF is received, close the socket immediately.

How to reproduce:

FakeFtp::Server.new(21212)
server.start

ftp_client = Net::FTP.new
ftp_client.connect('127.0.0.1', 21212)
ftp_client.login('user', 'password')
Benchmark.measure{ ftp_client.close }
=> #<Benchmark::Tms:0x00007fecfad73068
 @cstime=0.0,
 @cutime=0.0,
 @label="",
 @real=3.003513000003295,
 @stime=0.15119499999999997,
 @total=3.000451,
 @utime=2.849256>

...

Another run on this branch:

FakeFtp::Server.new(21212)
server.start

ftp_client = Net::FTP.new
ftp_client.connect('127.0.0.1', 21212)
ftp_client.login('user', 'password')
Benchmark.measure{ ftp_client.close }
=> #<Benchmark::Tms:0x00007fefe91c6688
 @cstime=0.0,
 @cutime=0.0,
 @label="",
 @real=0.0002390000008745119,
 @stime=8.900000000000574e-05,
 @total=0.0002629999999999022,
 @utime=0.00017399999999989646>

This is where the 3s of wait comes from https://github.com/ruby/ruby/blob/ruby_2_6/lib/net/ftp.rb#L1308

Furthermore, I suspect that this is the reason why integration and functional tests are disabled by default in this project. With this fix, the execution time shrinks significantly - from Finished in 21.24 seconds (files took 0.14215 seconds to load) to Finished in 0.21783 seconds (files took 0.14647 seconds to load)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant