Commit Graph

21 Commits

Author SHA1 Message Date
Johannes Weiss e102aa9ae9
add PipeChannel (#1138)
Motivation:

There are use-cases for SwiftNIO where there are no actual sockets but
rather two pipe file descriptors - one for input, one for output.
There's no real reason why SwiftNIO shouldn't work for those.

Modifications:

Add a PipeChannel.

Result:

More use-cases for SwiftNIO.
2019-10-16 22:06:55 -07:00
Johannes Weiss e540583b70 IntegrationTests: support more curl versions (#1163)
Motivation:

Some curl versions need a hostname even when connecting to UDS.

Modifications:

Always add a host name.

Result:

More compatibility.
2019-10-13 11:28:09 +01:00
Johannes Weiss 7767c4f6af
integration tests: remove python dependency (#1145)
Motivation:

The integration tests depended on python in order to print 80,000 x
characters.

Modifications:

Remove the python dependency and express the same with `dd` & `tr`.

Result:

Fewer dependencies.
2019-09-24 10:51:39 +01:00
Cory Benfield 768c3ab328
Avoid unnecessary allocation by way of tuple conversion. (#994)
Motivation:

Due to https://bugs.swift.org/browse/SR-10614, assigning an array containing a tuple type
to a variable that expects an array containing a different-but-compatible tuple type will cause
an allocation and copy of that array storage.

In some cases this is necessary, but we were doing it in the HTTPHeaders constructors, which meant
that the swift-nio-http2 code was hitting a hilariously over the top number of allocations.

Modifications:

- Change the internal storage type of HTTPHeaders to match the public constructor.

Result:

Fewer allocations when constructing HTTPHeaders
2019-05-03 21:12:19 +01:00
Johannes Weiss c90b159b4f HTTP1 example server: don't crash on empty file served (#962)
Motivation:

The file-io implementation in the example HTTP1 server just crashed on
empty file ;).

Modifications:

- fix the crash
- add integration test

Result:

fewer crashes
2019-04-10 19:28:09 +01:00
Johannes Weiss 22e6cd3c67
HTTP/1 headers simplification & cleanup (#857)
Motivation:

The HTTP/1 headers were quite complicated, CoW-boxed and exposed their
guts (being a ByteBuffer). In Swift 5 this is no longer necessary
because of native UTF-8 Strings.

Modifications:

- make headers simply `[(String, String)]`
- remove `HTTPHeaderIndex`, `HTTPListHeaderIterator`, etc

Result:

- simpler and more performant code
2019-03-06 18:11:40 +00:00
Ilya Puchka 0db96bf744 [NIOHTTP1Server] Use fixed default string to write in response and do not hardcode content length (#718)
* Use fixed default string to write in response and do not hardcode content length

Motivation:

Improve example code, resolve #714

Modifications:

Move hardcoded "Hello world" string to a constant property and removed hardcoding of content length header value

Result:

In example code content length will be written correctly when default response changes
2019-01-03 10:09:13 +00:00
Johannes Weiss 1ac60906f2 allow more time to close fds in integration tests (#611)
Motivation:

As #563 shows, sometimes in CI we don't reach the number of open
expected file descriptors. The current assumption is that this is just a
race when CI is slow. This allows up to 10s to reach the correct number
of open file descriptors.

Modifications:

- allow up to 10s to reach the correct number of fds

Result:

hopefully fixing #563 finally
2018-09-11 12:49:13 +01:00
Johannes Weiss 89603d6244 add Ubuntu 18.04 and Swift 4.2 support (#604)
Motivation:

We should support the latest and greatest.

Modifications:

- add Ubuntu 18.04 support (packages exist for Swift 4.2 only)
- add Swift 4.2 support (for Ubuntu 14.04, 16.04 and 18.04)

Result:

- supporting the latest stuff
2018-09-07 14:54:23 -07:00
Johannes Weiss adf8db6133 run a netstat if there's a socket leak in integration tests (#576)
Motivation:

We have a flaky integration test (#563) and I can't reproduce locally in
docker unfortunately. We have an `lsof` output but it just reads

    NIOHTTP1S 5157 root   12u  sock       0,7      0t0 113688082 can't identify protocol

which isn't very helpful. That's a known `lsof` on Linux but and the
recommendation is to run `netstat` which we now do.

Modifications:

add netstat output to the integration tests debugging info.

Result:

hopefully more information so we can soon fix #563
2018-08-16 10:13:20 +01:00
Johannes Weiß a5db2a6751
fix event loop hop between registration and activation of accepted channels (#389)
Motivation:

Once again, we had an extra event loop hop between a channel
registration and its activation. Usually this shows up as `EPOLLHUP` but
not so for accepted channels. What happened instead is that we had a
small race window after we accepted a channel. It was in a state where
it was not marked active _yet_ and therefore we'd not read out its data
in case we received a `.readEOF`. That usually leads to a stale
connection. Fortunately it doesn't happen very often that the client
connects, immediately sends some data and then shuts the write end of
the socket.

Modifications:

prevent the event loop hop between registration and activation

Result:

will always read out the read buffer on .readEOF
2018-05-04 15:48:08 +01:00
Johannes Weiß b109389c54 eagerly process input EOF/connection resets (fixes #277) (#286)
Motivation:

We had a number of problems:

1. We wanted to lazily process input EOFs and connection resets only
   when the user actually calls `read()`. On Linux however you cannot
   unsubscribe from `EPOLLHUP` so that's not possible.
2. Lazily processing input EOFs/connection resets wastes kernel
   resources and that could potentially lead to a DOS
3. The very low-level `Selector` interpreted the eventing mechanism's
   events quite a lot so the `EventLoop`/`Channel` only ever saw
   `readable` or `writable` without further information what exactly
   happened.
4. We completely ignored `EPOLLHUP` until now which on Unix Domain
   Socket close leads to a 100% CPU spin (issue #277)

Modifications:

- made the `Selector` interface richer, it now sends the following
  events: `readable`, `writable`, `readEOF` (input EOF), `reset`
  (connection reset or some error)
- process input EOFs and connection resets/errors eagerly
- change all tests which relied on using unconnected and unbound sockets
  to user connected/bound ones as `epoll_wait` otherwise would keep
  sending us a stream of `EPOLLHUP`s which would now lead to an eager
  close

Result:

- most importantly: fix issue #277
- waste less kernel resources (by dealing with input EOFs/connection
  resets eagerly)
- bring kqueue/epoll more in line
2018-04-16 19:36:47 +02:00
Johannes Weiß d94ab56d58 workaround ab (ApacheBench) in keep-alive mode (#260)
Motivation:

`ab -k` behaves weirdly: it'll send an HTTP/1.0 request with keep-alive set
but stops doing anything at all if the server doesn't also set Connection: keep-alive
which our example HTTP1Server didn't do.

Modifications:

In the HTTP1Server example if we receive an HTTP/1.0 request with
Connection: keep-alive, we'll now set keep-alive too.

Result:

ab -k doesn't get stuck anymore.
2018-04-10 18:28:10 +02:00
Norman Maurer 48cef4a59b
Implement lazy headers parsing (#291)
Motivation:

We are currently parsing each header eagly which means we need to convert from bytes to String frequently. The reality is that most of the times the user is not really interested in all the headers and so it is kind of wasteful to do so.

Modification:

Rewrite our internal storage of HTTPHeaders to use a ByteBuffer as internal storage and so only parse headers on demand.

Result:

Less overhead for parsing headers.
2018-04-10 14:57:58 +02:00
Cory Benfield 1bff3ab7e8 Enable our one disabled integration test. (#295)
Motivation:

We have one integration test left disabled, but actually it basically
already passes: it just expects the wrong format of error. We should
have all our integration tests enabled.

Modifications:

Enabled the test.
Changed the wording of the error it expected.

Result:

No disabled integration tests.
2018-04-10 10:07:39 +01:00
Cory Benfield 5b2ad2d921 Add support for automatic HTTP error reporting. (#268)
Motivation:

Currently the HTTP decoders can throw errors, but they will be ignored
and lead to a simple EOF. That's not ideal: in most cases we should make
a best-effort attempt to send a 4XX error code before we shut the client
down.

Modifications:

Provided a new ChannelHandler that generates 400 errors when the HTTP
decoder fails.
Added a flag to automatically add that handler to the channel pipeline.
Added the handler to the HTTP sample server.
Enabled integration test 12.

Result:

Easier error handling for HTTP servers.
2018-04-07 10:13:31 +02:00
Johannes Weiß ba470b7888
just set 127.0.0.1 as localhost's IPv4 address (#258)
Motivation:

Previously we tried to use `host` to determine localhost's IPv4 address.
That didn't work reliably in Docker and sometimes on macOS. Let's just
fix this to 127.0.0.1.

Modifications:

Hardcode localhost's IPv4 address as 127.0.0.1.

Result:

More stable test_16_tcp_client_ip
2018-03-30 17:47:54 +01:00
Cory Benfield 860a7d40a3 Add channel handler for server side pipelining. (#62)
Motivation:

HTTP pipelining can be tricky to handle properly on the server side.
In particular, it's very easy to write out of order or inconsistently
mutate state. Users often need help to handle this appropriately.

Modifications:

Added a HTTPServerPipelineHandler that only lets one request through
at a time.

Result:

Better servers that are more able to handle HTTP pipelining
2018-03-13 15:21:12 +00:00
Johannes Weiß 1065c9d38e
add license headers for shell scripts (#135)
Motivation:

Our shell scripts didn't have license headers but they should.

Modifications:

Add licensing headers to all shell scripts

Result:

Licensing clear for shell scripts too.
2018-03-12 17:12:47 +00:00
Cory Benfield 9ed09c0a5c Our sample HTTP server should respect HTTP keep-alive. (#115)
Motivation:

Currently our HTTP server almost always just assumes that keep-alive
is enabled. It really shouldn't, it should validate more carefully.
Additionally, it mishandles TCP half-close in a way that breaks with
netcat.

Modifications:

Added keep-alive tracking to all handlers and ensured that connections
will be closed after a response to a keep-alive request has been sent.
Also add support for handling TCP half-close.

Result:

Non-keep-alive connections will be closed by the server in all cases.
Half-closed connections will be appropriately managed.
2018-03-12 13:54:58 +01:00
Tom Doron 7d5dc67af8 scripts cleanup
motivation: nicer source tree

chanages:
* move scripts to scripts directory
* move integration tests to IntegrationTests directory and remove driver script
* add .sh extension to bash scripts
* adjust rio.yaml
2018-02-12 10:06:46 -08:00