Commit Graph

54 Commits

Author SHA1 Message Date
Michael Crosby
042635eccb Add onclose func
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-02-05 16:51:41 -05:00
Stephen Day
4d1bf6563c
Merge pull request #20 from stevvooe/pump-read-block
ttrpc: refactor channel to take a conn
2018-01-16 15:50:42 -08:00
Stephen J Day
c575201d9a
ttrpc: refactor channel to take a conn
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2018-01-16 15:29:07 -08:00
Stephen Day
7276d64f93
Merge pull request #21 from stevvooe/return-correct-error-close
ttrpc: return correct error on (*Client).Close
2018-01-12 16:38:48 -08:00
Stephen J Day
2c96d0a152
ttrpc: return correct error on (*Client).Close
Because `shutdownErr` will likely be `nil` in the close select branch,
returning it to waiters will result in the waiting `(*Client).Call`
returning `(nil, nil)`. This should take whatever is set for the client
as the exit condition, which is likely to be `ErrClosed`.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2018-01-12 16:21:27 -08:00
Stephen Day
d2710463e4
Merge pull request #19 from stevvooe/shutdown-client-err
ttrpc: return ErrClosed when client is shutdown
2018-01-09 15:00:59 -08:00
Stephen J Day
e963fd5a12
ttrpc: return ErrClosed when client is shutdown
To gracefully handle scenarios where the connection is closed or the
client is closed, we now set the final error to be `ErrClosed`. Callers
can resolve it through using `errors.Cause` to detect this condition.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2018-01-09 14:46:02 -08:00
Stephen Day
76e68349ad
Merge pull request #14 from AkihiroSuda/avoid-os-user
unixcreds: use euid instead of uid
2017-12-01 11:38:49 -08:00
Akihiro Suda
f2351f115b unixcreds: use euid instead of uid
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2017-12-02 03:58:03 +09:00
Stephen Day
334dad0199
Merge pull request #15 from justincormack/creds_linuxonly
SO_PEERCRED is Linux only
2017-12-01 10:55:09 -08:00
Justin Cormack
511f780fca
SO_PEERCRED is Linux only
BSD does have LOCAL_PEERCRED but x/sys.unix does not yet have support for it.
I will add support and do a proper fix later.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-12-01 10:54:41 -08:00
Stephen Day
961d4bc798
Merge pull request #17 from stevvooe/raw-conn
ttrpc: use syscall.RawConn to access fd over File
2017-12-01 10:19:14 -08:00
Stephen J Day
0fc9ed6ba0
ttrpc: use syscall.RawConn to access fd over File
Due to a performance drop when calling `(*net.UnixConn).File`, this
change uses the `syscall.RawConn` directly to call `Control` on the
socket. The result is there is no longer a performance penalty to using
unix socket credentials.

The benchmarks after this change are as follows:

```
goos: linux
goarch: amd64
pkg: github.com/stevvooe/ttrpc
BenchmarkRoundTrip-8                  	   50000	     22474 ns/op	    2593 B/op	      43 allocs/op
BenchmarkRoundTripUnixSocketCreds-8   	  100000	     22120 ns/op	    2593 B/op	      43 allocs/op
PASS
ok  	github.com/stevvooe/ttrpc	4.049s
```

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-12-01 10:00:50 -08:00
Stephen Day
45d16b41b5
Merge pull request #13 from stevvooe/glibc-not-static
ttrpc: use os.Getuid/os.Getgid directly
2017-11-30 20:30:37 -08:00
Stephen J Day
256c17bccd
ttrpc: use os.Getuid/os.Getgid directly
Because of issues with glibc, using the `os/user` package can cause when
calling `user.Current()`. Neither the Go maintainers or glibc developers
could be bothered to fix it, so we have to work around it by calling the
uid and gid functions directly. This is probably better because we don't
actually use much of the data provided in the `user.User` struct.

This required some refactoring to have better control over when the uid
and gid are resolved. Rather than checking the current user on every
connection, we now resolve it once at initialization. To test that this
provided an improvement in performance, a benchmark was added.
Unfortunately, this exposed a regression in the performance of unix
sockets in Go when `(*UnixConn).File` is called. The underlying culprit
of this performance regression is still at large.

The following open issues describe the underlying problem in more
detail:

https://github.com/golang/go/issues/13470
https://sourceware.org/bugzilla/show_bug.cgi?id=19341

In better news, I now have an entire herd of shaved yaks.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-30 20:21:50 -08:00
Stephen Day
af6e7491e5
Merge pull request #11 from stevvooe/unix-socket-credentials
ttrpc: implement unix socket credentials
2017-11-30 16:55:30 -08:00
Stephen J Day
d4983e717b
ttrpc: implement unix socket credentials
Because ttrpc can be used with abstract sockets, it is critical to
ensure that only certain users can connect to the unix socket. This is
of particular interest in the primary use case of containerd, where a
shim may run as root and any user can connection.

With this, we get a few nice features. The first is the concept of a
`Handshaker` that allows one to intercept each connection and replace it
with one of their own. The enables credential checks and other measures,
such as tls. The second is that servers now support configuration. This
allows one to inject a handshaker for each connection. Other options
will be added in the future.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-30 16:11:14 -08:00
Stephen J Day
8c92e22ce0
ttrpc: add round trip benchmark
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 21:33:13 -08:00
Stephen J Day
5859cd7b45
ttrpc: return buffers to pool
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 21:32:38 -08:00
Stephen Day
8f839f204c
Merge pull request #8 from stevvooe/handle-client-eof
ttrpc: refactor client to better handle EOF
2017-11-29 21:31:42 -08:00
Stephen J Day
b774f8872e
ttrpc: refactor client to better handle EOF
The request and response requests opened up a nasty race condition where
waiters could find themselves either blocked or receiving errant errors.
The result was low performance and inadvertent busy waits. This
refactors the client to have a single request into the main client loop,
eliminating the race.

The reason for the original design was to allow a sender to control
request and response individually to make unit testing easier. The unit
test has now been refactored to use a channel to ensure that requests
are serviced on graceful shutdown.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 21:00:50 -08:00
Stephen Day
78323657aa
Merge pull request #10 from stevvooe/remove-master-build
build: no need to build against Go master
2017-11-29 21:00:30 -08:00
Stephen J Day
f3f546b3dd
build: no need to build against Go master
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 20:58:11 -08:00
Stephen Day
eb3092a97e
Merge pull request #9 from stevvooe/build-badge
README: add build status badge
2017-11-29 17:28:05 -08:00
Stephen J Day
9992073108
README: add build status badge
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 17:26:55 -08:00
Stephen Day
30394a5e12
Merge pull request #7 from stevvooe/increase-maximum-message-length
ttrpc: increase maximum message length
2017-11-29 14:07:40 -08:00
Stephen J Day
2a1ad5f6c7
ttrpc: increase maximum message length
This change increases the maximum message size to 4MB to be inline
with the grpc default. The buffer management approach has been changed
to use a pool to minimize allocations and keep memory usage low.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 13:30:41 -08:00
Stephen J Day
ed51a24609
ttrpc: add test to ensure not found errors
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 11:23:20 -08:00
Stephen Day
7e38ac9e99
Merge pull request #4 from stevvooe/accept-loop-hardening
ttrpc: implement Close and Shutdown
2017-11-29 11:13:22 -08:00
Stephen J Day
b1feeec836
ttrpc: implement Close and Shutdown
This apples logic to correctly Close a server, as well as implements
graceful shutdown. This ensures that inflight requests are not
interrupted and works similar to the functionality in `net/http`.

This required a fair bit of refactoring around how the connection is
managed. The connection now has an explicit wrapper object, ensuring
that shutdown happens in a coordinated fashion, whether or not a
forceful close or graceful shutdown is called.

In addition to the above, hardening around the accept loop has been
added. We now correctly exit on non-temporary errors and debounce the
accept call when encountering repeated errors. This should address some
issues where `SIGTERM` was not honored when dropping into the accept
spin.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 11:03:51 -08:00
Stephen Day
8d40df6f6d
Merge pull request #5 from stevvooe/travis-build
build: add travis build file
2017-11-29 10:29:12 -08:00
Stephen J Day
d31419dd1d
build: add travis build file
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-29 10:24:42 -08:00
Stephen J Day
5e1096a4c2
ttrpc: better test for concurrency
Improve the test to conduct two concurrent calls. The test server now
just doubles the input and we use a unix socket to better represent what
will be used in production.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-27 21:19:57 -08:00
Stephen J Day
bdb2ab7a81
ttrpc: use odd numbers for client initiated streams
Following the convention of http2, we now use odd stream ids for client
initiated streams. This makes it easier to tell who initiates the
stream. We enforce the convention on the server-side.

This allows us to upgrade the protocol in the future to have server
initiated streams.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-27 18:18:25 -08:00
Stephen J Day
07cd4de2f2
ttrpc: correctly propagate error from response
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-22 12:06:18 -08:00
Stephen J Day
a763db9d1f
ttrpc: add required codec.go
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-21 21:44:39 -08:00
Stephen J Day
7f752bf263
ttrpc: handle concurrent requests and responses
With this changeset, ttrpc can now handle mutliple outstanding requests
and responses on the same connection without blocking. On the
server-side, we dispatch a goroutine per outstanding reequest. On the
client side, a management goroutine dispatches responses to blocked
waiters.

The protocol has been changed to support this behavior by including a
"stream id" that can used to identify which request a response belongs
to on the client-side of the connection. With these changes, we should
also be able to support streams in the future.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-21 21:38:38 -08:00
Stephen J Day
2a81659f49
ttrpc: remove use of typeurl
Rather than employ the typeurl package, we now generate code to
correctly allocate the incoming types from the caller. As a side-effect
of this activity, the services definitions have been split out into a
separate type that handles the full resolution and dispatch of the
method, incuding correctly mapping the RPC status.

This work is a pre-cursor to larger protocol change that will allow us
to handle multiple, concurrent requests.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-21 18:03:52 -08:00
Stephen J Day
2d76dba1df
plugin: move generator to separate package
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-16 19:22:21 -08:00
Stephen J Day
d7306a0f0b
README: clarifications and TODOs
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-15 18:32:08 -08:00
Stephen J Day
809ed493d8
ttrpc: remove unused imports
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-15 17:28:18 -08:00
Stephen J Day
bd8c759c72
ttrpc: update examples after name change
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-15 17:09:36 -08:00
Stephen J Day
f147d6ca77
ttrpc: rename project to ttrpc
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-15 17:04:16 -08:00
Stephen J Day
1bfe6fb8f6
mgrpc: address error on accept
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-15 17:02:44 -08:00
Stephen J Day
52978c11e8
mgrpc: decrease size of channel buffers
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-15 17:01:30 -08:00
Stephen J Day
484a09bfa0
mgrpc: fill out client generation functionality
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-15 17:00:35 -08:00
Stephen J Day
76ad1535fb
README: explain differences with grpc
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-15 16:58:33 -08:00
Stephen J Day
f32bbe9f11
mgrpc: generate first example service
With this changeset, we have the first end to end generated server and
client. Most of the necessary types are in place and working. There are
a lot of details to work out, but this would be enough for to exercise
the end to end flow.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-14 18:56:09 -08:00
Stephen J Day
71e9170d05
mgrpc: mock out workflow for generated code
The server unit test now manually mocks much of the generated code for a
given service, including back registration of the service. We avoid
having a package-level global descriptor in favor of a closures for the
handler dispatch function.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-14 18:23:40 -08:00
Stephen J Day
538d13ce1b
README: update overview of project and provide usage
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-14 13:12:30 -08:00