Commit Graph

44 Commits

Author SHA1 Message Date
Jin Dong
4729a87007 Upgrade go, dependency, CI versions
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
2024-12-30 01:42:33 +00:00
Krisztian Litkey
ed6c3ba082
server_test: add Serve()/Shutdown() race test.
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
2024-09-16 09:51:56 +03:00
Krisztian Litkey
84e1784f34
server_test: fix error message in TestOversizeCall.
Fix copy-pasted error message in unit test.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
2024-08-19 19:29:04 +03:00
Krisztian Litkey
e0cd801116 server_test: wait for OnClose in TestClientEOF.
In the test for client Call failing with ErrClosed on a closed
server, wait for the client's OnClose handler to get triggered
to make sure closing the socket had properly been administered
on the client's side. Otherwise trying a new Call() might fail
with some other error than ErrClosed, for instance ENOTCONN.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
2023-07-27 17:59:04 +03:00
Phil Estes
36fd7c3f33
Merge pull request #132 from austinvazquez/add-test-logging
Rework deadline assertion logging to be more clear
2023-03-08 12:46:43 -05:00
Austin Vazquez
19445fddca Fix server shutdown logic
Simplify close idle connections logic in server shutdown to be more
intuitive. Modify add connection logic to check if server has been
shutdown before adding any new connections. Modify test to make all
calls before server shutdown.

Signed-off-by: Austin Vazquez <macedonv@amazon.com>
2023-02-27 16:45:35 +00:00
Austin Vazquez
5a7c8fbf15 Rework deadline assertion logging to be more clear
Make `TestServerRequestTimeout` deadline assertion log print expected
and actual values in the same format for more clear troubleshooting.

Signed-off-by: Austin Vazquez <macedonv@amazon.com>
2023-02-25 00:26:47 +00:00
Kazuyoshi Kato
ca27f484bd Make checkServerShutdown verbose
TestServerShutdown is often failing on Windows.
This change may help troubleshooting easier.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2023-01-27 00:02:02 +00:00
Derek McGowan
d28bc92657 Introduce streaming to client and server
Implementation of the 1.2 protocol with support for streaming. Provides
the client and server interfaces for implementing services with
streaming.

Unary behavior is mostly unchanged and avoids extra stream tracking just
for unary calls. Streaming calls are tracked to route data to the
appropriate stream as it is received.

Stricter stream ID handling, disallowing unexpected re-use of stream
IDs.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2022-04-07 17:11:40 -07:00
Derek McGowan
f8e8cc43e6 Server test show sys error
Signed-off-by: Derek McGowan <derek@mcg.dev>
2022-03-04 18:17:11 -08:00
Derek McGowan
40a76139bd
Merge pull request #104 from kzys/windows-wsarecv
Log the error's underyling errno if there is
2022-02-21 14:00:17 -08:00
Kazuyoshi Kato
44dfd7fdbd Log the error's underyling errno if there is
This test occasionally fails on Windows. This commit logs extra
information about the error to understand the situation better.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2022-02-21 21:33:56 +00:00
Kazuyoshi Kato
d240c5005f Use google.golang.org/protobuf instead of github.com/gogo/protobuf
This change replaces github.com/gogo/protobuf with
google.golang.org/protobuf, except for the code generators.

All proto-encoded structs are now generated from .proto files,
which include ttrpc.Request and ttrpc.Response.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2022-02-16 23:11:27 +00:00
Derek McGowan
f7a2e09ef8 Fix lint issues
Cleanup server test

Signed-off-by: Derek McGowan <derek@mcg.dev>
2022-01-21 12:04:30 -08:00
zounengren
81faa3ee80 replace pkg/errors from vendor
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
2021-09-25 22:46:36 +08:00
Derek McGowan
b649452727
Merge pull request #85 from kzys/non-linux
Make "go test" and "go build" work on macOS
2021-05-24 15:27:06 -07:00
Kazuyoshi Kato
a4b18e0db8 Make "go test" work on macOS
Abstract sockets, procfs and unix.Ucred are only available on Linux.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2021-05-21 16:58:39 -07:00
Kazuyoshi Kato
fede9db17c Return Unimplemented when services or methods are not implemented
gRPC has UNIMPLEMENTED status code that indicates a requested method
is not implemented. However ttrpc was returning codes.NotFound which
could be returned when a request entity was not there.

This fix changes the status code from codes.NotFound to
codes.Unimplemented to disambiguate and be more compatible with gRPC.

Fixes #80.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2021-05-21 15:51:33 -07:00
Wei Fu
225de2c936 client: add UserOnCloseWait function
ttrpc provides WithOnClose option for user and ttrpc will call the
callback function when connection is closed unexpectedly or the ttrpc
client's Close() method is called. containerd runtime plugin uses it
to handle cleanup the resources created by containerd shim.

But the ttrpc client's Close() is only trigger and the shim's cleanup
resource callback is called asynchronously, which might make part of
resources leaky. There is an example from containerd-runtime-v2 for
runc:

```happy
[Task.Delete goroutine]         [cleanupCallback goroutine]

call ttrpc client.Close() -->

                                  read bundle and call runc delete

delete bundle
```

If the cleanupCallback is called after deleting bundle, the callback
will fail to call runc delete. If there is any running processes, the
resource becomes leaky.

```unhappy
[Task.Delete goroutine]         [cleanupCallback goroutine]

call ttrpc client.Close() -->

delete bundle

                                  failed to read bundle and call runc delete
```

In order to avoid this, introduces the UserOnCloseWait to make sure that
the cleanupCallback has been called synchronously, like:

```
[Task.Delete goroutine]         [cleanupCallback goroutine]

call ttrpc client.Close() -->

wait for callback

                               read bundle and call runc delete

                          <--  finish sync

delete bundle
```

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2020-09-07 23:09:55 +08:00
fupan.lfp
4f8e36d414 server: add a connections leak unit test
Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
2020-04-21 11:20:11 +08:00
Michael Crosby
d4834b09f5 Revert "Copy codes and status from grpc project"
This reverts commit f02233564f.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-10-28 14:46:51 -04:00
Michael Crosby
f02233564f Copy codes and status from grpc project
This copies the codes and status package from grpc as it is the only references
to the grpc project from ttrpc. This will help ensure that API breaking changes
in grpc do not affect ttrpc.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-10-28 12:33:50 -04:00
Phil Estes
1fb3814edf
Merge pull request #42 from crosbymichael/client
Refactor close handling for ttrpc clients
2019-06-13 14:33:16 -04:00
Michael Crosby
694de9d955 metadata as KeyValue type
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-06-13 18:06:27 +00:00
Michael Crosby
3afb82bd27 Fix error handling with server shutdown
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-06-13 17:19:47 +00:00
Maksym Pavlenko
04523b9d2c Rename headers to metadata
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
2019-05-24 17:02:38 -07:00
Maksym Pavlenko
5926a92b70 Support headers
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
2019-05-23 13:34:04 -07:00
Georgi Sabev
96dcf73d20 Handle EOF to prevent file descriptor leak
Currently the EOF that the server gets when a client connection is
closed is being ignored, which means that the goroutine that is
processing the client connection will never exit. If it never exits
it will never close the underlying unix socket and this would lead
to a file descriptor leak.

Signed-off-by: Georgi Sabev <georgethebeatle@gmail.com>
2019-05-10 15:35:37 +03:00
Brian Goff
a364f44e55 Add support for request timeout propgation.
Adds a new field to the `Request` type which specifies a timeout (in
nanoseconds) for the request. This is propagated on method dispatch as a
context timeout.

There was some discussion here on supporting a broader "metadata" field
(similar to grpc) that can be used for other things, but we ended up
with a dedicated field because it is lighter weight and expect it to be
used pretty heavily as is.... metadata may be added in the future, but
is not necessary for timeouts.

Also discussed using a deadline vs a timeout in the request and decided
to go with a timeout in order to deal with potential clock skew between
the client and server. This also has the side-effect of eliminating the
protocol/wire overhead from the request timeout.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2019-01-07 12:43:52 -08:00
Michael Crosby
01ed7d8777 Add context to Serve
This is to seed a new context on the serve method

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-02 11:36:10 -04:00
Michael Crosby
0690b20898 Add apache license to files
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-06-27 17:49:06 -04: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 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 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
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 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 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 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
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
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
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
42ff40f1f1
mgrpc: initial implementation of server
With this change, we define a simple server and client framework to
start generating code against. We define a simple handler system with
back registration into the server definition.

From here, we can start generating code against the handlers.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-11-14 12:18:06 -08:00