1319 Commits
Author SHA1 Message Date
Johannes Weiss 334815f658 HTTPDecoder: no error on unclean EOF on upgrade (#1063)
Motivation:

Previously we thought that if we have some bytes left that belong to an
upgraded protocol, we should deliver those as an error. This is
implemented on `master` but not in any released NIO version.
However, no other handler sends errors on unclean shutdown, so it feels
wrong to do it in this one very specific case (EOF on inflight upgrade
with data for the upgraded protocol)

Modifications:

Remove the error again.

Result:

Less behaviour change to the last released NIO version.
2.4.0
2019-07-11 17:29:03 +01:00
Johannes Weiss 7a250a225e HTTPDecoder: Don't invoke left overs strategy on EOF (#1061)
Motivation:

Do as we documented and invoke the leftovers strategy only when the
handler is removed.

Modifications:

Don't invoke leftovers on EOF (which isn't something the user can
control).

Result:

- Fewer crashes
- should fix https://github.com/IBM-Swift/Kitura-WebSocket-NIO/issues/35
2019-07-10 12:58:28 -04:00
Konrad `ktoso` Malawski ed3bca3131 check breakages: fail loudly when unable to checkout tag (#1060)
One line description of your change

Motivation:

When using the script ad hoc to verify something you may have forgotten to pull all tags,
the script then fails mysteriously in silence and no output. Detective work can then lead the script mysteriously stopping after a checkout:

```
+ cd /tmp/.check-api_1Q1rvO/repo
+ git checkout 1.1.0
$ ...
```

which reminds you to perform a fetch; it would be nicer if it told us about the issue explicitly though.

Modifications:

Don't silence `git checkout` all error output, though use quiet mode so no progress is printed.

Result:

Script fails nicer and reminds you to perform a git fetch if you forgot to do so.

e.g.

```
[5/5] Merging module Metrics
error: pathspec '1.1.0' did not match any file(s) known to git
```
2019-07-09 15:51:40 +01:00
Liam Flynn 64c673b6e8 Add a WebSocket client upgrader. (#1038)
Motivation:

There is a client protocol upgrader but, unlike the server protocol upgrader, it does not have a WebSocket protocol as part of the project.

Modifications:

Made the magic WebSocket GUID public to the WebSockets project.
Added a NIOWebSocketClientUpgrader.
Added tests for the upgrader.
Updated the Linux test script files.

Result:

The project now has a WebSocket client upgrader to match the WebSocket server upgrader.
2019-07-08 03:55:02 -04:00
George Barnett 07e7e01c76 Check jq is available before checking API breakages (#1058)
* Check jq is available before checking API breakages

Motivation:

If jq wasn't installed the API breakage script would erronesouly say
that there were no breaking API changes. That's pretty bad.

Modifications:

Check jq is available before running the check. Updated the usage
message to specify that a Swift 5.1+ toolchain is required.

Result:

More correctness.
2019-07-04 18:47:21 +01:00
Konrad `ktoso` Malawski c49d5e7a5e EventLoopPromise.completeWith(Future), mirroring ELF.cascade(to:) #1052 (#1053)
Motivation:

EventLoopFuture and EventLoopPromise are symmetric APIs and for easier
discoverability of being able to complete a promise with a future it
is helpful to have a mirror of future.cascade put onto promise.

Modifications:

- Adds ELP.completeWith(ELF)

Result:

It is now possible to complete a promise with a future,
and not only cascade a future to a promise.
2019-06-28 12:23:12 +01:00
Julian Lettner 803d36b7f3 Tiny test code cleanup (#1051) 2019-06-27 07:49:46 +01:00
Johannes Weiss 069fcde4c5 docs: add forgotten modules (#1050)
Motivation:

Embarrassingly, we forgot a bunch of modules in the documentation.

Modifications:

Add the forgotten modules.

Result:

Better docs.
2019-06-23 16:33:47 +01:00
Johannes Weiss 7f20464df3 enable TCP_NODELAY by default (#1020)
Motivation:

Networking software like SwiftNIO that always has explicit flushes
usually does not benefit from having TCP_NODELAY switched off. The
benefits of having it turned on are usually quite substantial and yet we
forced our users for the longest time to enable it manually.

Quite a bit of engineering time has been lost finding performance
problems and it turns out switching TCP_NODELAY on solves them
magically.

Netty has made the switch to TCP_NODELAY on by default, SwiftNIO should
follow.

Modifications:

Enable TCP_NODELAY by default.

Result:

If the user forgot to enable TCP_NODELAY, their software should now be
faster.
2.3.0
2019-06-19 18:04:01 +01:00
Johannes Weiss 1549cd7e87 ByteBuffer.get/readData: Heuristic when to copy/not copy (#1046)
Motivation:

Previously, ByteBuffer tried to never copy the bytes when transferring
to a `Data`. For small copies that's definitely not a good choice
because it means an extra allocation.

Modifications:

- introduce `ByteTransferStrategy` so the user can choose
- make a heuristic: copy is less than 256kB, try not to copy above

Result:

More sensible defaults.
2019-06-19 17:46:25 +01:00
Cory Benfield 22a368730c Return accidentally removed API. (#1045)
Motivation:

We accidentally removed NIOFileHandle(path:) when we added some
arguments with default values to it. This doesn't normally break source,
but in some weird edge cases it can, and it's bad form to remove it.

Modifications:

- Replace the missing function

Result:

Fewer highly unlikely source breakages.
2019-06-19 17:15:21 +01:00
Johannes Weiss 448a0ba8c8 analyze_performance_results: switch to "min" instead of "mean" (#1044)
Motivation:

Mean is not a great aggregation function because it's not resilient
against outliers at all, so let's switch to min.

Modifications:

Switch 'mean' to 'min' for aggregation.

Result:

Aggregation function that's more resilient against outliers.
2019-06-19 16:10:43 +01:00
Johannes Weiss bc816050cc don't close server socket if fcntl(O_NONBLOCK) throws EINVAL (#1041)
Motivation:

Darwin does sometimes hand us back an (as of the docs) illegal error
code of EINVAL. So far, NIO has done the non-sensical thing of closing
the server socket as a result.

Modifications:

Just close the accepted socket, leave the server socket open, and fire
the error through the pipeline.

Result:

- fixes #1030
- better behaviour
2019-06-19 15:42:18 +01:00
Liam Flynn 856fe3be1a Updated the embedded channel tests to write to the input and output multiple times. (#1033)
Motivation:

The current test check that the buffer can be written to and then that it is cleared.
They do not check that once the buffer is cleared, it can be written to again.

Modifications:

Added a test for both the inbound and outbound buffer to check multiple writes to each buffer.

Result:

We can not be sure that multiple writes to either the inbound or outbound buffers on the embedded channel works.Updated the embedded channel tests to write to the input and output buffers multiple times.
2019-06-19 15:20:28 +01:00
Johannes Weiss 39e60dd694 5.1-DEVELOPMENT-SNAPSHOT-2019-06-17-a (#1043) 2019-06-19 08:43:05 +01:00
Johannes Weiss 7829542cc5 remove platform availability again (#1042)
Motivation:

The platform availability that we recently introduced caused problems
because it would require all downstream projects to define the same or
narrower platform availability to still compile with NIO which would
make this very disrupting and also SemVer major.

Modifications:

Remove the platform availability declarations.

Result:

No SemVer breakages.
2019-06-18 20:21:12 +01:00
Johannes Weiss 3e7198f52c when making a socket non-blocking, get & OR flags (#1040)
Motivation:

Previously, we would just `F_SETFL, O_NONBLOCK` which would erase all
possibly pre-existing flags which isn't great.

Modifications:

First get the existing flags and then do `F_SETFL, existingFlags |
O_NONBLOCK`.

Result:

Possibly helps with #1030, definitely better style.
2019-06-18 15:37:38 +01:00
Liam Flynn 5f1432db38 Add self where required WebSocket server tests. (#1034)
Motivation:

To ensure the swift-NIO style for self is followed within the WebSocket tests.
Modifications:

Altered the style within the WebSocketServerEndToEnd tests.
Result:

Slightly more readable code.
2019-06-18 11:25:51 +01:00
Johannes Weiss bf2598d193 iOS & simulator compatibility (#1037)
Motivation:

We should have better iOS compatibility.

Modifications:

- make all OS-conditional imports the same
- don't check TSI_S_ESTABLISHED (which is unavailable on iOS)
- update availability to reflect the OS versions we actually support
- make sure temporary UDS paths aren't too long

Result:

better iOS compatibility
2019-06-18 10:38:39 +01:00
Liam Flynn 57785e6d9c An HTTP upgrader class for a client pipeline. (#1001)
* Reorder ‘channel active’ calls to the same order as `_ChannelInboundHandler` and their likely chronological order.

Motivation:
When first viewing the example classes, coming to the ‘read’ method first, leaves the subject unclear as to what the method is ‘reading’.
It is preferable to view something being sent first, and then to view the reading of the response.
It also matches the call order against the protocol making it a little easier for those unfamiliar with the protocol to see which methods have been implemented.

Modifications:
Moved channel active calls to be top of the class.
Despite the diff there are no actual code modifications.
UDP Client changed to indent using spaces to match rest of project. Incidental change.

Result:
The examples are slighter clearer to read, particularly for newcomers to swift-no as the calls are in a logical chronological order.

* Fix an error in the upgrader and its tests which checked the connection header incorrectly.

Motivation:
To correct the logic in the upgrader. Previously it checked if the upgraders required headers include the connection header. Now it checks that the connection header value was present as a separate header in the incoming request.
To prepare the class naming for the presence of a client upgrader.

Modifications:
Slight change in server upgrader handler logic with accompanying tests.
Renamed upgrader and test files to include the word ‘server’.
Ran the linux test script.

Result:
The server upgrader now checks for the presence of the connection header value as a header of its own.

* Rename WebSocketServer upgrader to make the naming clearer and make way for a client version.

Motivation:

To make the web socket upgrader naming clearer, particularly once we add a client version.

Modifications:

Rename WebSocketUpgrader too WebSocketServerUpgrader.

Result:

Improved clarity of naming on the web socket upgrader.

* Adds  correct naming conventions to NIOWebSocketServerUpgrader. Sets back an incorrect fix (non-fix).

* Move deprecation for NIOWebSocketServerUpgrader typealias out of API shims file.

* Makes HTTPEncoder removable.
Adds a client upgrade handler with tests.
Adds the ability to use a client upgrader to the client setup.
Initial linux file update.

* Allow assertContains to be accessed publicly, so that it can be used in the client side tests.

* Update tests to remove server upgrader from client tests.
Change client tests to use Embedded channel.
Update HTTPUpgradeConfiguration class name to be NIOHTTPServerUpgradeConfiguration
Few other small stylistic changes.

* Removed awaiting upgrader state.
Removed future from handle upgrade call as is synchronous.
Removed protocol iterator from handle upgrade call as is not required by the client.

* Ensure that the client handler calls for the HTTPPipeline are backwards compatible.
Ensure that incoming promises to the handler write call are completed.
Neaten the upgrade header formation to remove looping.
Improve the correctness of the upgrade error throwing.

* Update scripts to match new unit tests.

* Change the documentation for HTTPServerPipeline to remove nil options which have now been removed.

* Restore an incorrectly added server pipeline comment change and make it to the client pipeline instead.

* Raise the allocation limits in the docker images to allow the tests to pass.
2019-06-16 11:10:12 +01:00
Liam Flynn f5084352c6 Rename the EndToEndTests in the WebSocket project to WebSocketServerEndToEndTests. (#1032)
Motivation:

To make the web socket server end to end tests class more descriptive.
This will allow ‘WebSocketClientEndToEndTests’ or other end to end tests to be added at a later date.

Modifications:

Renames the class and filename for ‘EndToEndTests’ to ‘WebSocketServerEndToEndTests’

Result:

The nomenclature now allow for other end to end tests to be added.
2019-06-11 19:22:02 -07:00
Simon Evans dfe4318c50 When testing for an IPv6 Loopack interface try resolving ::1 (#1028)
Motivation:

On an Ubuntu18 system with a loopback interface configured with both
an IPv4 and IPv6 address, SocketAddress(ipAddress: "::1", port: 0) will
succeed, indicating that an IPv6 interface is configured. However if the
ethernet address has only an IPv4 address, getaddrinfo("::1", ...) will
fail even though the host resolution should work. This appears to be a
bug in the getaddrinfo() config.

This means that the tests will proceed assuming IPv6 is available, but
later tests that attempt to resolve "::1" will fail unexpectedly.

Modifications:

Change the ipv6Loopback test to attempt a resolution initially and if
this fails then assume that an IPv6 loopback is not available.

Result:

The Multicast.testCanJoinBasicMulticastGroupIPv6 test is skipped instead
of failing.
2019-06-07 16:33:35 -07:00
George Barnett 8aaaaab4fa Add an optimization tips document. (#1024)
Motivation:

NIO doesn't offer any tips of on how to write performant code. After
discussing with @weissi we decided it would be useful to gather and
document some useful tips and tricks.

Modifications:

Started an optimization tips document.

Result:

Easier for NIO users to write performant code.
2019-06-05 07:48:57 -07:00
Johannes Weiss a04da61854 alloc test: don't delete tmpdir (#1026)
Motivation:

The allocation tests shouldn't delete their working directory because
that's where you would navigate to debug them. Usually, they're run
through the integration tests which automatically clean up anyway.

Modifications:

Don't delete work dir

Result:

Easier to debug
2019-06-05 06:12:14 -07:00
George Barnett 93df43e5ec Fix incorrect closure names in documentation. (#1025)
Motivation:

I noticed some closures were referred to by the wrong name in the
documentation.

Modifications:

Updated the documentation to use the correct names.

Result:

More correct documentation.
2019-06-04 15:23:21 +01:00
Cory Benfield 3c9c4d59ec Make EmbeddedChannel.isWritable mutable. (#1023)
Motivation:

When testing programs that check flow control state, it's useful to be
able to control the results of that check. However, right now it's not
possible to set the flow control state of an EmbeddedChannel: it's just
always true. That's not super helpful.

Modifications:

Make EmbeddedChannel.isWritable a stored property that can be changed.

Result:

Better testing.
2019-06-03 22:23:40 +01:00
Johannes Weiss 8112653e28 alloc counters: disallow too high limits (#1022)
Motivation:

For the allocation counter tests to be as useful as possible, we should
disallow limits that are too high, we should capture the allocation
count very close to where it actually is.

Modifications:

Don't allow any allocation counter test to allocate fewer than
'limit - 1000' allocations.

Result:

Better limits.
2019-06-02 18:17:58 +01:00
Johannes Weiss 19aa7bf77d 5.1-DEVELOPMENT-SNAPSHOT-2019-05-29-a (#1021) 2019-05-30 14:08:30 +01:00
Johannes Weiss 2f98289125 ChannelPipeline benchmark (#1002)
Motivation:

We need good microbenchmarks.

Modifications:

Add a ChannelPipeline microbenchmark.

Result:

More benchmarks.
2019-05-30 13:26:25 +01:00
Cory Benfield 25bb2831ac Extend the ByteToMessageDecoder documentation. (#1019) 2019-05-28 10:21:43 +01:00
Cory Benfield 54935344c4 Provide CircularBuffer.modify(_:_:). (#1009)
Motivation:

When using CircularBuffer as a storage object it would be helpful to be
able to write directly into the underlying storage. As the _modify
accessor is currently underscored and not really safe for us to use, the
next best option is to write a function that takes advantage of the
_modify access on the underlying Array. This patch provides that
function.

Modifications:

- Implemented CircularBuffer.modify(_:_:)

Result:

It'll be possible to use a fast function to access the underlying Array
storage.
2019-05-26 09:14:57 +01:00
Johannes Weiss ca9278670f AcceptHandler: don't swallow close errors when quiescing (#1015)
Motivation:

When receiving the ChannelShouldQuiesceEvent event, the AcceptHandler
correctly closes the ServerChannel. However, if that fails, it swallows
the error which is incorrect.

Modifications:

Don't swallow the error, send it through the pipeline.

Result:

More correct.
2019-05-24 18:00:17 +01:00
Johannes Weiss 0357118bee Add check_no_api_breakages, a script to check public API breakages (#1016)
Motivation:

It's incredibly hard not to accidentally break the public API, so let's
automate that :).

Modifications:

Add the first version of a public API check script.

Result:

Fewer public API breakages.
2019-05-23 13:15:46 +01:00
tomer doron c1aff57ba4 add performance analysis docker-compose setup and script (#1013)
motivation: prepare to run performance tests in ci

changes:
* add performance-test docker-compose task
* add script that can parse the performance test suite results and compare between two result-sets
* add generic shell docker-compose task
2019-05-23 11:37:21 +01:00
tomer doron ed50f8a41e replace redundant commands in docker-compose files with generic one (#1010)
Motivation: keep it DRY

Modifications: move redundant commands from 18-04-5.0 and 16.04-5.1 to the generic task definitions
2.2.0
2019-05-21 09:12:05 -07:00
Cory Benfield 925ab655be Fix misleading comment on ELF.map (#1012)
Motivation:

We left a doc comment on EventLoopFuture.map that caused confusion by
misleadingly claiming that it could handle throwing functions. The
operation that handles throwing functions is flatMapThrowing.

Modifications:

- Removed the misleading comment and pointed users to flatMapThrowing
    instead.

Result:

Less user confusion.
2019-05-21 09:45:46 +01:00
Johannes Weiss a836b78c7a prune docker compose files (#1007)
Motivation:

We still had a bunch of docker files for NIO on Swift versions that NIO2
doesn't actually work on. Also we had allocation counter limits in
places where they don't mean anything.

Modifications:

Prune all the useless information.

Result:

Less configuration.
2019-05-18 07:10:26 +01:00
Johannes Weiss 7623b5e4f1 undo tiny public API breakage (#1008)
Motivation:

In #957 we accidentally broke the API just a little bit. We turned the
`ByteToMessageHandler.init` from

    public init(_ decoder: Decoder)

into

    public init(_ decoder: Decoder, maximumBufferSize: Int? = nil)

This looks totally benign and in almost all cases because of the default
argument, you wouldn't notice the API breakage. However, it's possible
to write code that works in NIO 2.0.0 but breaks in NIO 2.1.0. For
example

    let g: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init
    let h: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init(_:)

Modifications:

According to SemVer, this releases a patch that unbreaks the public API.

Result:

No API breakages (checked with `swift-api-digester` which also found the
breakage in the first place).
2019-05-17 17:20:43 +01:00
Johannes Weiss ccc459a86e TestUtils: EventCounterHandler (#1005)
Motivation:

In many unit tests, it's important to count the events. So far we have
many many ad-hoc handlers to do so but having one that counts all events
would be handy.

Modifications:

Add `EventCounterHandler` to count all events travelling the
`ChannelPipeline`.

Result:

Easier unit testing
2019-05-17 14:09:03 +01:00
George Barnett 6023c65341 Allow adding a sequence of headers to HTTPHeaders (#1004)
* Allow adding a sequence of headers to HTTPHeaders

Motivation:

When combining two collections of headers, adding each pair one-by-one
using add(name:value:) can cause multiple unnecessary reallocations of
the underlying array.

Modifications:

Provide two additional add methods to HTTPHeaders: one to add a sequence
of name/value pairs and another to add the headers from another
HTTPHeaders, both of which use `append(contentsOf:)` on the underlying
array to avoid additional reallocations.

Result:

Fewer reallocations when adding multiple headers.

* Fix incorrect documentation, make add<S: Sequence>(contentsOf:) @inlineable

* Reserve capacity and add sequentially instead of using append(contentsOf:)

* Add tests and missing @usableFromInline
2019-05-16 17:21:21 +01:00
Romain Pouclet c59c193ea7 Add an always method on EventLoopFuture (#981)
Add an `always` method on EventLoopFuture

Motivation:

https://github.com/apple/swift-nio/issues/665

Modifications:

* Add `always` in EventLoopFuture.swift
* Add tests

Result:

NIO Users will be able to use `.always` to, well, always run an action
wether the future succeed or not.
2019-05-15 12:02:23 +01:00
Johannes Weiss 5513bb202a Create NIOTestUtils & add B2MD verifier (#939)
Motivation:

When writing B2MDs, there are a couple of scenarios that always need to
be tested: firehose feeding, drip feeding, many messages, ...

It's tedious writing those tests over and over again for every B2MD.

Modifications:

- Add a simple B2MD verifier that users can use in unit tests.
- Add a new, public `NIOTestUtils` module which contains utilities
  mostly useful for testing. Crucially however, it does not depend on
  `XCTest` so it can be used it all targets.

Result:

Hopefully fewer bugs in B2MDs.
2019-05-10 17:29:13 +01:00
Johannes Weiss d1c7cd0bac alloc counters: propagate tmp dir (#1000)
Motivation:

The allocation counter tests should default to using the integration
tests' tmp dir.

Modifications:

Propagate the right tmp dir.

Result:

fewer orphaned tmp dirs lying around in case of error.
2019-05-10 17:04:53 +01:00
Johannes Weiss a2ecd50863 don't hardcode NIO modules (#999)
Motivation:

The new allocation counter suite hardcoded a few things:
- the NIO and NIOHTTP1 modules
- no extra dependencies apart from the repo you're in

Modifications:

remove these hardcoded things.

Result:

allocation counter script works for nio-http2
2019-05-10 15:12:21 +01:00
Johannes Weiss 0e37ada7cc B2MDError: nest PayloadTooLargeError (#998)
Motivation:

New public NIO types must be nested in existing ones or `NIO` prefixed.
This wasn't the case for ByteToMessageDecoderPayloadTooLargeError

Modifications:

nest PayloadTooLargeError into ByteToMessageDecoderError

Result:

we stick to our rules.
2.1.0
2019-05-09 15:29:52 +01:00
Johannes Weiss 5d1d59868d new alloc counter tests (#996) 2019-05-09 14:27:29 +01:00
Johannes Weiss e0679121a6 HTTPDecoder: don't crash if response has no headers (#997)
Motivation:

With HTTP/1.0 and EOF framing it's possible to have a HTTP response that
doesn't have any headers. HTTPDecoder unfortunately fell flat on its
face and crashed the program if that happened.

Modifications:

- don't expect headers on responses
- add tests for that
- rename the state machine cases to reflect a request and response
  parsing

Result:

fewer crashes.
2019-05-07 15:38:58 +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 9e451149ca lower allocation limits for Swift 5.1 (#995)
Motivation:

Swift 5.1 shows much fewer allocations, let's tighten the limits.

Modifications:

Tighten the allocation limits on 5.1.

Result:

We'll catch allocation regressions much more easily.
2019-05-03 19:10:25 +01:00
Cory Benfield ae5564e4de Improve MarkedCircularBuffer performance. (#993)
Motivation:

While CircularBuffer has an inlinable implementation to improve performance, MarkedCircularBuffer
never got enhanced to have it. This harms performance in many core NIO libraries which heavily use
MCB, forcing heap allocations on almost all MCB operations.

Modifications:

- Make basically everything on MarkedCircularBuffer inlinable.

Result:

Faster code.
2019-05-03 11:00:45 +01:00