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.
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.
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.
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.
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
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.
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.
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.
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.
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
* 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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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
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.
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.
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).
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
* 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
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.
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.
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.
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
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.
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.
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
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.
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.
Motivation:
We should test all available Swift versions, including snapshots.
Modifications:
Add docker compose file for Swift 5.1.
Result:
More testing.
Motivation:
The new file RW opening facilities didn't have any tests and it didn't
let you specify arbitrary POSIX flags.
Modifications:
- Add tests.
- Let users specify both POSIX flags & mode.
Result:
Better code quality.
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.
Motivation:
Structures that users can't create don't give them much value.
Modifications:
- Make the initializer public.
- Remove that godforsaken @testable import.
Result:
ChannelOptions.Storage sparks joy.
Motivation:
https://github.com/apple/swift-nio/issues/966
Modifications:
- Add a `handler(type:)` method on ChannelPipeline
- Add a test in ChannelPipelineTest
Result:
Provides a nicer way to get a typed handler directly from the pipeline
Closes#966
Motivation:
https://github.com/apple/swift-nio/issues/701
Modifications:
* Add `init(rawValue:)`
* Add `rawValue`
* Add tests in HTTPTypesTest.swift
Result:
Users no longer have to write their own conversion methods.
Motivation:
Because of #600, many users will start leaking Channels because they
don't close on error.
Modifications:
* Add ChannelHandlerError
* Add ChannelHandlerErrorTest
Result:
User will have access to an handler to use to automatically close
the channel in case of unhandled errors