Commit Graph

110 Commits

Author SHA1 Message Date
John Eikenberry 8e0c78ade5 fix spelling error in comment 2017-07-03 13:14:51 -07:00
John Eikenberry 737aa1dc61 Fixes #181: client deadlock on server death
The client was deadlocking if you killed the server when a file transfer
was occuring. The problem occured when you had many requests sent and
were waiting on responses when the server dies. The errors for all those
pending requests get sent along the response channel which is also used
for the errors reported by the new requests being made. The new request
channel send is in the same loop as the channel reading, so when it
blocked due to all other errors filling the channel it deadlocked the
program.

There were 2 possible fixes, changing the new request error channel
usage to be in a separate goroutine to keep it from blocking the loop or
to increase the size of the buffer to handle all the errors. This
implements the latter.

Included is a test that reproduces the problem most of the time. Due to
the required timing of the issue, it was impossible to reproduce 100% of
the time.
2017-06-29 11:27:52 -07:00
John Eikenberry ca043ca452 add ReadFrom benchmark 2017-06-25 19:21:59 -07:00
John Eikenberry 8f9da7f630 quick fix to get benchmarks running
benchmarks were broken due to double closing of a channel in some tests.
I just commented out the problematic closes which probably means it's
leaking in the tests but at least they run now. Should probably try to
figure out what happened here at some point.
2017-03-14 12:27:51 -07:00
Catalin Tanasescu 43d52d4faa ported Glob method from filepath - https://golang.org/pkg/path/filepath/#Glob 2017-02-18 14:26:32 -08:00
John Eikenberry cfb6d5c5b2 Add tests for deadlocks in Read and WriteTo
Just like issues reported in #145
2017-02-13 17:20:40 -08:00
John Eikenberry 14f0a222dd Tests to replicate deadlock bug in Write/ReadFrom
github issue #145

A deadlock will occur in cases when using client.Write or client.ReadFrom,
it has 2 network issues in a row, and it is starting a new loop to send
more concurrent packets.
2017-02-13 00:32:33 -08:00
John Eikenberry bc4cce8bc3 basic ReadFrom test 2017-02-12 19:37:13 -08:00
Dave Cheney c5050bbe83 removed unused code 2016-06-15 11:33:39 +10:00
Dave Cheney 982656642c Introduce netpipe (#105)
netPipe provides a pair of io.ReadWriteClosers connected to each other.
The functions is identical to os.Pipe with the exception that netPipe
provides the Read/Close guarentees that os.File derrived pipes do not.
2016-05-29 17:22:48 +10:00
Dave Cheney f3fc26f1c3 General server cleanups (#103)
- no need to initalise mutexes, their zero value is valid
- make NewServer simpler, 90% of use cases already had an
  io.ReadWriteCloser, in the single case that it it is easy to provide a
  simple wrapper.
2016-05-29 16:32:05 +10:00
Mark Sheahan 7e2e721fdf use ssh_FXP_STAT for Stat(); previously Stat() and Lstat() were both Lstat() 2016-04-26 12:07:21 -07:00
Matt Layher 8e47c759f5 server: remote rootDir parameter, as it does nothing 2016-01-16 12:41:01 -05:00
Matt Layher 403657b31e server: use functional options for NewServer 2016-01-11 11:52:51 -05:00
Matt Layher 051287be6d *: remove all named and naked returns 2016-01-07 15:56:04 -05:00
Matt Layher b348482b1a *: golint (part 1) 2016-01-07 12:10:24 -05:00
Dave Cheney 9e66bf3ae2 Merge pull request #72 from mdlayher/master
client: make Client.{Lstat,Open,Stat} satisfy os.IsNotExist
2016-01-04 12:14:20 +01:00
Matt Layher 3fa7dab0f1 client: add normaliseError, make Client.{Lstat,Open,Stat} satisfy os.IsNotExist 2016-01-03 16:10:58 -05:00
Dave Cheney 94fb4ddd0c Add -testserver permutation
Fixes #69

io.Pipe is unbuffered and provides a poor replacement for a net.Conn, use an os.Pipe instead.

Also skip some tests which don't work under the Go server as it runs in process.
2016-01-02 10:28:56 +01:00
Dave Cheney 53002ca6c0 Check that writing to a read only file returns an error
Fixes #28
2015-12-25 18:46:07 +01:00
Matthew Sykes f5afc8315a Add Getwd to client 2015-12-22 09:04:46 -05:00
Dave Cheney 167ae32ca7 Handle osx returning EPERM not ENOTDIR
Fixes #57

Also fix the integration tests to run on darwin by default.
2015-12-22 13:34:21 +09:00
DrJosh9000 f76972fd8d rm extra f.Name in test 2015-09-25 18:17:46 +10:00
Josh Deprez a003aa966d Add test for new Name method 2015-09-25 18:05:59 +10:00
Mark Sheahan d80ae36051 rmdir and symlink packet handling 2015-09-07 01:05:16 -07:00
Mark Sheahan 7bb2083ca9 Address review comments; about to change decodePacket() 2015-09-06 23:55:15 -07:00
Mark Sheahan 0d8e136458 removing sftp server to client layer; using straight os.* calls 2015-09-06 19:36:47 -07:00
Mark Sheahan 348ee1a469 truncate + darwin VFS test 2015-08-04 22:21:35 -07:00
Mark Sheahan 2f3ef8b897 Merge branch 'master' into server 2015-08-04 21:11:01 -07:00
Mark Sheahan f4c4138a0e update client integration tests for more coverage 2015-08-04 20:47:26 -07:00
Mark Sheahan 0f2bc1aa17 server is passing the client integration tests now. I don't understand the ATTRs field, it has a name in it. 2015-07-31 23:09:51 -07:00
Mark Sheahan 435f753792 readdir, rename, remove 2015-07-31 15:46:13 -07:00
Mark Sheahan 2888b4a6b1 implement read 2015-07-29 17:24:24 -07:00
Dave Cheney 587af18cfc Fix integration tests on darwin 2015-07-15 16:36:15 -07:00
Dave Cheney c1748e2776 Fix typo in slice creation.
Fixes #43
2015-06-15 20:12:08 +10:00
Glenn Griffin 29600148e4 Handle recvPacket in a single goroutine.
Previously recvPacket would be invoked in several goroutines. This meant
that when multiple concurrent requests were in flight there were N
goroutines each waiting on recvPacket. For optimal throughput the goal
is to send a new request as quickly as possible once a response is
received. The previous mechanism worked counter to this because the
goroutine sending new requests would be competing against N recvPacket
goroutines that may become runnable as data streams in. Having a single
goroutine responsible for recvPacket means that the recv and send
goroutines will ping-pong back and forth optimizing throughput.

This changes shows a ~10-25% increase in throughput in the the *Delay*
benchmark tests.

$ go test -bench=. -integration
PASS
BenchmarkRead1k	       2	 840068631 ns/op	  12.48 MB/s
BenchmarkRead16k	      20	  72968548 ns/op	 143.70 MB/s
BenchmarkRead32k	      30	  56871347 ns/op	 184.38 MB/s
BenchmarkRead128k	     100	  34150953 ns/op	 307.05 MB/s
BenchmarkRead512k	     100	  15730685 ns/op	 666.59 MB/s
BenchmarkRead1MiB	     200	  10462421 ns/op	1002.24 MB/s
BenchmarkRead4MiB	     200	   7325236 ns/op	1431.47 MB/s
BenchmarkRead4MiBDelay10Msec	      10	 186893765 ns/op	  56.11 MB/s
BenchmarkRead4MiBDelay50Msec	       2	 907127114 ns/op	  11.56 MB/s
BenchmarkRead4MiBDelay150Msec	       1	2708025060 ns/op	   3.87 MB/s
BenchmarkWrite1k	       1	1623940932 ns/op	   6.46 MB/s
BenchmarkWrite16k	      10	 174293843 ns/op	  60.16 MB/s
BenchmarkWrite32k	      10	 120377272 ns/op	  87.11 MB/s
BenchmarkWrite128k	      20	  54592205 ns/op	 192.08 MB/s
BenchmarkWrite512k	      50	  66449591 ns/op	 157.80 MB/s
BenchmarkWrite1MiB	      50	  70965660 ns/op	 147.76 MB/s
BenchmarkWrite4MiB	      50	  69234861 ns/op	 151.45 MB/s
BenchmarkWrite4MiBDelay10Msec	       5	 276624260 ns/op	  37.91 MB/s
BenchmarkWrite4MiBDelay50Msec	       1	1318396552 ns/op	   7.95 MB/s
BenchmarkWrite4MiBDelay150Msec	       1	3918416658 ns/op	   2.68 MB/s
BenchmarkCopyDown10MiBDelay10Msec	      10	 152240808 ns/op	  68.88 MB/s
BenchmarkCopyDown10MiBDelay50Msec	       2	 715003188 ns/op	  14.67 MB/s
BenchmarkCopyDown10MiBDelay150Msec	       1	2116878801 ns/op	   4.95 MB/s
BenchmarkCopyUp10MiBDelay10Msec	      10	 192748258 ns/op	  54.40 MB/s
BenchmarkCopyUp10MiBDelay50Msec	       2	 691486538 ns/op	  15.16 MB/s
BenchmarkCopyUp10MiBDelay150Msec	       1	1997162991 ns/op	   5.25 MB/s
BenchmarkMarshalInit	 2000000	       644 ns/op
BenchmarkMarshalOpen	 3000000	       562 ns/op
BenchmarkMarshalWriteWorstCase	   20000	     75166 ns/op
BenchmarkMarshalWrite1k	  500000	      3862 ns/op
ok  	github.com/pkg/sftp	71.174s
2015-06-02 13:13:32 -07:00
Glenn Griffin fdbec907ff Add integration tests that measure how throughput varies with latency.
This clearly shows the impact high latency networks have on the
throughput of sftp transfers. The current benchmark results on my
machine are:

$ go test -bench=. -integration
PASS
BenchmarkRead1k	      20	  93028268 ns/op	 112.72 MB/s
BenchmarkRead16k	     100	  14912438 ns/op	 703.16 MB/s
BenchmarkRead32k	     100	  12282661 ns/op	 853.71 MB/s
BenchmarkRead128k	     100	  10550935 ns/op	 993.83 MB/s
BenchmarkRead512k	     100	  12970518 ns/op	 808.44 MB/s
BenchmarkRead1MiB	     100	  11526693 ns/op	 909.70 MB/s
BenchmarkRead4MiB	     100	  15761135 ns/op	 665.30 MB/s
BenchmarkRead4MiBDelay10Msec	       1	2662626928 ns/op	   3.94 MB/s
BenchmarkRead4MiBDelay50Msec	       1	12977334971 ns/op	   0.81 MB/s
BenchmarkRead4MiBDelay150Msec	       1	38777294968 ns/op	   0.27 MB/s
BenchmarkWrite1k	       5	 235318220 ns/op	  44.56 MB/s
BenchmarkWrite16k	      50	  57347520 ns/op	 182.85 MB/s
BenchmarkWrite32k	      30	  66151560 ns/op	 158.51 MB/s
BenchmarkWrite128k	      20	  86642733 ns/op	 121.02 MB/s
BenchmarkWrite512k	      20	  72648883 ns/op	 144.34 MB/s
BenchmarkWrite1MiB	      20	  87145317 ns/op	 120.33 MB/s
BenchmarkWrite4MiB	      50	  64098344 ns/op	 163.59 MB/s
BenchmarkWrite4MiBDelay10Msec	       1	3360676836 ns/op	   3.12 MB/s
BenchmarkWrite4MiBDelay50Msec	       1	16321294488 ns/op	   0.64 MB/s
BenchmarkWrite4MiBDelay150Msec	       1	48731747397 ns/op	   0.22 MB/s
BenchmarkCopyDown10MiBDelay10Msec	       1	3369680836 ns/op	   3.11 MB/s
BenchmarkCopyDown10MiBDelay50Msec	       1	16228310257 ns/op	   0.65 MB/s
BenchmarkCopyDown10MiBDelay150Msec	       1	48505306499 ns/op	   0.22 MB/s
BenchmarkCopyUp10MiBDelay10Msec	       1	3393474907 ns/op	   3.09 MB/s
BenchmarkCopyUp10MiBDelay50Msec	       1	16273951972 ns/op	   0.64 MB/s
BenchmarkCopyUp10MiBDelay150Msec	       1	48461724780 ns/op	   0.22 MB/s
BenchmarkMarshalInit	 2000000	       779 ns/op
BenchmarkMarshalOpen	 2000000	       645 ns/op
BenchmarkMarshalWriteWorstCase	   20000	     70954 ns/op
BenchmarkMarshalWrite1k	  300000	      5072 ns/op
ok  	github.com/pkg/sftp	296.179s
2015-06-02 10:48:10 -07:00
Dave Cheney 50631306d7 Push c.mu.Lock/Unlock down to sendRequest
Also includes gofmt cleanups
2015-05-23 17:10:22 +10:00
Maximilian Pachl 267a179e16 added integration test for client.StatVFS 2015-05-16 00:54:02 +02:00
Alexander Neumann c70639c68b Add benchmarks for Read() and Write() 2014-10-09 20:29:58 +02:00
Alexander Neumann 5af3cfa4ea Add sftp.NewClientPipe()
This method returns a Client from a pair of pipes.  This can be used for
connecting to an SFTP server over TCP/TLS or by using the system's ssh
client program (e.g. via exec.Command).

An Example function is added, and the client integration test uses the
function.
2014-09-30 00:49:01 +02:00
Alexander Neumann c01862b019 Add integration test flag for sftp binary path 2014-09-29 23:36:14 +02:00
Alexander Neumann 47028b98ef Run gofmt on client_integration_test.go 2014-09-29 23:36:13 +02:00
Dave Cheney f881033388 missed one MarshalBinary func 2014-09-28 12:52:54 +10:00
Dave Cheney 9ad0511df9 Added integration tests for all the MarshalBinary impls. 2014-09-28 12:48:54 +10:00
Sean Treadway b5d9767c0a Consistent puncutation, names and constants
* European sentence punctuation, consistent with package docs
  * Match os.SEEK_* constants instead of numeric constants from io.Seeker
  * Consistent (shorter) receiver name for quickcheck value
2014-06-13 10:22:04 +02:00
Sean Treadway 68aec0278e Implement io.Seeker for *sftp.File
Test that reads at the seeked offset of sftp.File are consistent with
the reads of offset of os.File for the same file.

Error conditions and undefined seeks are not tested.
2014-06-11 21:17:53 +02:00
Dave Cheney b8aa2fe3d1 Fixed Read, removed ReadAt
ReadAt should be replaced by Seek when the fs interface provides it.
2013-11-15 22:04:14 +11:00
Dave Cheney fd27263026 Added hashing check 2013-11-15 21:47:28 +11:00
Dave Cheney 7af199b09e Added more comprehensive read test 2013-11-15 21:17:11 +11:00
Dave Cheney 4d6ea4f122 Added OpenFile support
Close #3
2013-11-14 15:32:21 +11:00
Dave Cheney 31b82445b2 Switched back to kr/fs 2013-11-11 12:57:03 +11:00
Dave Cheney b45014c025 Added ReadAt tests 2013-11-08 22:11:02 +11:00
Dave Cheney 216912b085 Added Client.sendRequest, and more tests 2013-11-08 21:56:25 +11:00
Dave Cheney d4d73b4a58 Added better walk tests 2013-11-08 21:24:50 +11:00
Dave Cheney a54570ce91 Added Write tests 2013-11-08 21:00:26 +11:00
Dave Cheney 0a82d462b2 more integration tests 2013-11-06 19:29:59 +11:00
Dave Cheney 44d7769a0d added File.Stat/fstat coverage 2013-11-06 16:03:08 +11:00
Dave Cheney fc1d4adce0 more integration tests 2013-11-06 15:53:14 +11:00
Dave Cheney ec6ff9e634 Initial integration tests 2013-11-06 15:40:35 +11:00