Commit Graph

49 Commits

Author SHA1 Message Date
John Eikenberry aedf9a737a Fix #192 all Request methods use pointer recivers
Prevents subtle copy bugs and made the 1 required Request copy explicit.
2017-08-20 17:03:15 -07:00
John Eikenberry cffd2fabb0 Fix #195 Handler wrappers deal with errors
TLDR; have the Handler wrappers generate the response packets for the
errors instead of returning the errors.

Errors from the handers was returned up the stack to the request-server
handler call. In cases of errors the packet for the error was then
generated using the passed in packet (the incoming packet).

For file read/write/list operations the incoming packet data (includeing
ID) is put in a queue/channel so that it can be handled by the same file
handling code returned by the handler.

Due to gorouting scheduling, in some cases the packets in the channel
won't line up with the incoming packets. That is the worker that took an
incoming packet with one ID might respond with a packet with a different
ID. This doesn't matter as the reply order of packets doesn't matter.

BUT when this response packet that doesn't match IDs with the incoming
packet system returns an error, it uses the incoming packets ID to
generate the error packet. So the error response would use that ID and
the packet from the queue, once processed, would also use that ID
(because on success  it uses the ID from the packet in the queue).

This patch fixes the issue by having the code that works with the
packets, either incoming or from the queue, generate the error packet.
So there is no chance of them getting out of sync.
2017-08-20 16:15:01 -07:00
John Eikenberry bc6b56aae0 packageManager to use pointer receivers everywhere
Had a problem with getting a copy because a value receiver called a
pointer receiver.
2017-08-20 15:23:55 -07:00
John Eikenberry 26ceac758e add os.ErrNotExist handling into statusFromError
And remove errorAdapter() as this makes it unnecessary.
2017-08-20 14:54:45 -07:00
sandreas 653e2f1043 Merge branch 'master' into master 2017-08-13 17:00:45 +02:00
andreas 4d7bb970c4 Resolved conflict with SftpServerWorkerCount
Splitted cleanPath into cleanPacketPath and cleanPath for better handling of slashes in file paths
Added test for cleanPath func
Removed code duplication => filepath.ToSlash(filepath.Clean(...)) => cleanPath(...)
Fixed tests for runLs to match year or time
Renamed constants to fit hound rules
2017-08-13 14:00:08 +02:00
John Eikenberry 733115c415 Fixes #184; better fix for file batching
I didn't like how the initial fix for #184 required the handler author
to track the token/offset for the filelist. I came up with a way to do
it that mimic'd the FileReader handler interface using a method
something like ReaderAt except for file lists.

changed MaxFileinfoList to a var for testing and tweaking

Renaming FileInfoer interface to FileLister.
FileInfoer -> FileLister
Fileinfo -> Filelist
2017-08-10 15:36:41 -07:00
Andreas 939f0f3934 Fixed possible double slash in request 2017-08-10 12:50:08 +02:00
Andreas 505f2cb49e Fixed issues with backslashes on windows systems 2017-08-09 17:25:44 +02:00
John Eikenberry e97b9a47e1 avoid data race in worker creation
There is a data race with the waitgroup (wg) object used to synchronize
the workers with the server exit. The workers called wg.Add()
asynchronously and it was possible for the Wait() to get hit before any
of the Add() calls were made in certain conditions. I only ever saw this
sporatically in the travis tests.

This fixes it by making the wg.Add() calls synchronous.
2017-07-03 17:53:55 -07:00
John Eikenberry 07d4ed1b5c don't copy lock
govet pointed out that I was copying a lock when creating/assigning the
connection object. It didn't cause any issues, but was a bad practice.
2017-07-03 17:45:58 -07:00
John Eikenberry adb5b39283 convert fsetstat to setstat in request-server
Handle fsetstat in same was a fstat, by pulling path from stored file
info and processing in that form. Makes handlers simpler while
preserving functionality.
2017-04-24 21:53:56 -07:00
John Eikenberry 4cfaeaf9b7 fix hang on fstat calls in request server
Support fstat by converting to a standard Stat call and processing that.
I didn't want to add another special case to the request backend, I
wanted to keep it only having to support Stat.
2017-04-24 21:39:51 -07:00
John Eikenberry ced55b1bf0 request-server to use new packet ordering code
The 2 servers now use all the same packet managing code to ensure
ordered processing and reply packets.
2017-04-23 14:27:25 -07:00
Pavel Borzenkov 9aa225fc15 Don't copy Server struct in sendPacket/sendError
Server struct contains Mutex which might be copied in inconsistent
state. Avoid this by declaring methods on pointer receiver.

This calms down go race detector.

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
2017-04-05 14:15:57 -07:00
John Eikenberry 5152c21cf9 integrate packageManager into servers 2017-03-23 16:15:04 -07:00
John Eikenberry 51cb116815 better name: packet -> requestPacket 2017-03-23 16:15:04 -07:00
John Eikenberry 7e76fd5451 close reader/writer when deleting request 2017-02-18 18:20:37 -08:00
John Eikenberry 117dcd5916 refactor request setup into init and update
More understandable and adds additional type safety.
2017-02-18 18:20:37 -08:00
John Eikenberry ce4586e8a5 convert request to be pass by value
Encapsulate stateful data into sub-structures with pointer references
from the Request structure. This allows me to pass by value in most
cases to keep non-stateful (write once) data data race free and tightly
controlling access to stateful data to ease locking.
2017-02-18 18:20:37 -08:00
John Eikenberry 889f6b990a getRequest should use an RLock 2017-02-18 18:20:37 -08:00
John Eikenberry f4432147d1 fix issue with leaking requests in handle cache 2017-02-18 18:20:37 -08:00
John Eikenberry 23acc34b25 change back to using int as handle key
Was using a filename as a placeholder for something that would allow for
stateless servers but decided the amount of work wasn't worth it at this
point. So I went back to the auto-inc number as it doesn't have the size
issues (max handle length is 256).
2017-02-18 18:20:37 -08:00
John Eikenberry bf94760e22 golinter suggested name fix 2017-02-18 18:20:37 -08:00
John Eikenberry 9962211713 linter fixes 2017-02-18 18:20:37 -08:00
John Eikenberry abd44045b6 comment out tracing/debugging prints 2017-02-18 18:20:37 -08:00
John Eikenberry 69cd74c3d1 os.ErrorNotExist should convert to ssh_FX_NO_SUCH_FILE 2017-02-18 18:20:37 -08:00
John Eikenberry 80a7e6e68a gofmt tweaks 2017-02-18 18:20:37 -08:00
John Eikenberry 60d6f54546 Add requestserver.Close() method 2017-02-18 18:20:37 -08:00
John Eikenberry f53058b17a require handlers as arg to NewRequestServer 2017-02-18 18:20:37 -08:00
John Eikenberry d235f09578 all paths should be absolute 2017-02-18 18:20:36 -08:00
John Eikenberry 43bb004893 formatting fixes 2017-02-18 18:20:36 -08:00
John Eikenberry 27cff420db remove old comments/notes 2017-02-18 18:20:36 -08:00
John Eikenberry e8d7a278de move realpath handling into request-server 2017-02-18 18:20:36 -08:00
John Eikenberry f6042b29bc remove redundant 'request' from handle method name 2017-02-18 18:20:36 -08:00
John Eikenberry f1ec5cd102 isOpener interface to simplify type checking/testing 2017-02-18 18:20:36 -08:00
John Eikenberry 2b0671ce69 clean up worker function 2017-02-18 18:20:36 -08:00
John Eikenberry e307459f45 factor out response struct 2017-02-18 18:20:36 -08:00
John Eikenberry 42095a108c move request.populate call out of handler
makes handler testing much simpler as it only needs a populated request
instead of faked packets.
2017-02-18 18:20:36 -08:00
John Eikenberry f3ebdef6de factor out request channels 2017-02-18 18:20:36 -08:00
John Eikenberry a253a470f0 move open handling to packet level 2017-02-18 18:20:36 -08:00
John Eikenberry cdfae2dc1d pass/store handlers on request vs server 2017-02-18 18:20:36 -08:00
John Eikenberry fd475710b5 add response channel from req to packet handler
working to decouple request handling from packet handling. adding a
response channel means I don't need to handle sending packets.

eliminated need for cur_pkt and sendError() on request objects so far.
2017-02-18 18:20:36 -08:00
John Eikenberry 39e544ecfe make RequestServer.Handlers public 2017-02-18 18:20:36 -08:00
John Eikenberry 37052567c8 name fixes 2017-02-18 18:20:36 -08:00
John Eikenberry e19ab67571 fleshed out processing handlers 2017-02-18 18:20:36 -08:00
John Eikenberry 06735900ce reworked handler/interfaces to new minimal set 2017-02-18 18:20:36 -08:00
John Eikenberry 06bf237860 reworked in branch and liked it 2017-02-18 18:20:36 -08:00
John Eikenberry d1634cd6a7 initial request server commit
builds but doesn't run
2017-02-18 18:20:36 -08:00