Motivation:
ByteBuffer had a very bad (exploitable!) security vulnerability if the
following conditions are all true:
- user writes to a ByteBuffer which is a slice (slice.lowerBound != 0)
- the slice is uniquely referenced (ie. the buffer that it was sliced
from is gone)
- the write triggers a re-allocation
Then the slice is actually _larger_ than the overall available capacity
so another write to said ByteBuffer could end up out of bounds.
Modifications:
- fixed slice reallocation
Result:
- fixed security vulnerability
Motivation:
EventLoopFuture.and had serious threading issues if the EventLoops
weren't the same.
Modifications:
Fixed the threading issues and tested them properly.
Result:
Hopefully `and` and `andAll` now don't crash if you use them across
EventLoops.
Motivation:
We did not verify that fireErrorCaught(...) was called for recoverable errors while accept new sockets.
Modifications:
Verify errorCaught is called.
Result:
Better test.
Motivation:
We should not close the DatagramChannel when recvfrom fails with ECONNREFUSED / ENOMEM. The former may be caused by a previous sendto and the other may be recoverable by just stop reading for some time.
Modifications:
- Special handle ECONNREFUSED and ENOMEN to not close the channel.
- Add unit tests
Result:
More robust datagram support.
Motivation:
For servers NIO had a race where when you start tearing down the
`ServerSocketChannel` and at roughly the same time a client connects, we
would not fully bring that channel up, nor tear it down. That lead to
open channels being deallocated which leads to a crash as that's an
illegal state.
Modifications:
Made sure newly accepted channels get closed if the
`ServerSocketChannel` is already clsing.
Result:
No crashes anymore when a client connects to a closing server.
Motivation:
We returned port numbers directly from the sockaddr structures but
they're in network byte order. Our code only read them correctly when
presenting, oops.
Modifications:
Corrected the port number reading and tested that.
Result:
Port numbers should now be correct.
Motivation:
Often accept errors are recoverable over time as for example you may just run out of file descriptors. Because of this it may be useful to just "delay" accepts a bit to recover.
Modifications:
Add ChannelHandler which will backoff accepts.
Result:
Be able to recover from accept errors gracefully.
Motivation:
At the moment its possible that channelRead is triggered even if autoRead is never changed to true and no read() is triggered.
Modifications:
- Always register with .none on the Selector and then just call readIfNeeded0()
- Only register for EPOLLRDHUP if .read, .write or .all is used.
- Add test case.
Result:
Fixes https://github.com/apple/swift-nio/issues/160.
Motivation:
The current HTTP server helpers are not modular, meaning that each
time we add a new first-party HTTP handler we need to add a brand new
method. Additionally, they do not currently compose, so if you want
assistance with HTTP pipelining *and* to support HTTP upgrade you are
out of luck.
Modifications:
Deprecate the two existing server helpers.
Add a new server helper that can be extended to support all of the
possible features that users may want in their HTTP pipelines.
Result:
Users will have a single place to go that can be used to configure
their HTTP server pipeline, and that understands how the different
handlers fit together in a complete pipeline.
Motivation:
In certain cases it would be useful to be able to access the current EventLoop (which is tied to a thread).
Modifications:
- Add MultiThreadEventLoopGroup.currentEventLoop
- Add tests
Result:
Fixes [#59]
Motivation:
The HTTP pipeline may contain other HTTP protocol specific handlers,
beyond just the ones that the upgrade handler knows explicitly. It should
be possible to get the upgrade handler to remove those at the right time.
Modifications:
Add extra support for removing handlers.
Result:
It'll be possible for the HTTP upgrade logic to remove things like the
pipelining handler at upgrade time.
Motivation:
It is often useful to find a handler of a given type even when you
aren't holding a reference to that handler. This patch allows us to
do that.
Modifications:
Add context(handlerType:) function to the channel pipeline.
Result:
Users can find handlers of a given type in a pipeline.
Motivation:
Clang 3.6 doesn't know about `_Nonnull` which breaks compilation for our
C atomics.
Modifications:
Defined `_Nonnull` as `__attribute__((nonnull))` which seems to already
be available before clang 3.7.
Result:
NIO compiles with clang 3.6 as the default C compiler.
Motivation:
In a few instances, we have code that ignores a `()` argument in a
closure with this syntax:
{ (_: Void) in
whilst that's a bit odd, it shouldn't be wrong and Swift 4.0.x is also
totally happy with it. The latest Swift 4.1 candidates however are not
and also there's a better way of spelling this:
{ () in
and in some cases even just
{
Modifications:
Removed instances of `{ (_: Void) in`
Result:
Compiles with `swift-4.1-DEVELOPMENT-SNAPSHOT-2018-03-12-a`
Problem: Documentation for classes like _ChannelInboundHandler are not accesible via the official API documentation pages
Cause: GitHub treats the gh-pages branch as Jekyll
Solution: Turn off Jekyll by adding a .nojekyll file to the gh-pages branch
Motivation:
Websockets is a major protocol in use on the web today, and is
particularly valuable in applications that use asynchronous I/O
as it allows servers to keep connections open for long periods of
time for fully-duplex communication.
Users of NIO should be able to build websocket clients and servers
without too much difficulty.
Modifications:
Provided a WebsocketFrameEncoder and Decoder that can serialize and
deserialize Websocket frames.
Result:
Easier use of websockets.
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
Motivation:
We should not close the server socket when accept fails with ECONNABORTED / EMFILE / ENFILE, ENOBUFS. ENOMEM as generally speaking these may be "recoverable" once some existing connections were closed for example. It's possible to implement a backoff strategy for these with a ChannelHandler.
Modifications:
- Special handle of ECONNABORTED / EMFILE / ENFILE, ENOBUFS. ENOMEM for ServerSocketChannel.
Result:
Not close servet socket for errors from which it is possible to recover.
Motivation:
Reduce memory footprint of BaseSocket
Modifications:
- made isOpen a computed var from 'descriptor >= 0'
- BaseSocket init check precondition 'descriptor >= 0'
Result:
- isOpen no longer requires storage space
- close() sets descriptor to -1
- descriptor property changed from let to var
Motivation:
Currently we only supporting adding channel handlers at the front
or the end of the pipeline. This is potentially a bit frustrating:
it becomes impossible to insert handlers relative to a specific
point in the pipeline, which limits users ability to code generic
pipeline modification operations.
Modifications:
Added two new methods to ChannelPipeline, specifically
add(handler:before:) and add(handler:after:). Also performed a
substantial internal refactoring of the ChannelPipeline handler
adding code to ensure that all operations go through the same
logical path, redefining add(handler:first:) in terms of adding
either before tail or after head.
Result:
Users will be able to insert channel handlers at any point in a
ChannelPipeline, so long as they are able to point at a handler
already in that pipeline.
Motivation:
Reduce system calls on Linux required for configuring sockets as
nonblocking.
Modifications:
- expose accept4 as CNIOLinux_accept4
- add Linux internal enum for exposing Linux specific API
- wrap CNIOLinux_accept4 with Linux.accept4
- expose SOCK_NONBLOCK and SOCK_CLOEXEC on Linux
- add setNonBlocking parameter to BaseSocket.newSocket
- add setNonBlocking parameter to ServerSocket.accept
Result:
Servers and clients on Linux will use fewer system calls creating new sockets.
Motivation:
Simplifies the code by putting the iterator in HTTPHeader's namespace.
Additionally, removing the type erasure should result in more performant code as `AnyIterator` is an optimization barrier. The type erasure did not appear to be adding an abstraction benefit.
Modifications:
Nested (internal) type `HTTPHeaderIterator` as `HTTPHeader.Iterator`
Explicit rather than inferred types for `Element` and `Iterator`.
Eliminated `AnyIterator` wrapper from `makeIterator()`
Added lower-priority version that still returns `AnyIterator` for source compatibility.
Result:
Unless caller was explicitly typing the iterator, should have no noticeable impact other than performance.
Motivation:
We need license headers at the top of all files but we didn't
automatically check for it in all source files.
Modifications:
Check for the full licensing header in all files (Swift, C & Shell).
Result:
If we're missing a licensing header a PR won't turn green.
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.
properly destroy pthread mutex and cond
Motivation:
properly destroy pthread mutex and cond
Modifications:
call pthread_mutex_destroy in Lock deinit
call pthread_cond_destroy in ConditionLock deinit
Result:
Lock and ConditionLock deinit may crash if locks are still in use.
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.
Motivation:
Reduce memory footprint of BaseSocket and FileHandle
Modifications:
- made isOpen a computed var from 'descriptor >= 0'
- add withSocketpair to TestUtils
- use real pipe and socketpair file descriptors for tests
- BaseSocket and FileHandle init check precondition 'descriptor >= 0'
Result:
- isOpen no longer requires storage space
- close() sets descriptor to -1
- descriptor property changed from let to var
- tests will need to use valid file descriptors
Motivation:
In order to target the latest version of Swift and address this issue https://github.com/apple/swift-nio/issues/83
Modifications:
Set the Swift version to the latest (4.0.3)
Result:
Uniform version of Swift across the Ubuntu Docker image and a passing
test suite on all target platforms
Motivation:
When building our docker image a lot of warnings showed up.
Modification:
- Ensure we not try to start services on installation
- Redirect STDERR
- Remove some commented lines
Result:
Less warnings during building the docker image.
Motivation:
We can cleanup the code by removing return keywords in closures sometimes.
Modifications:
Remove return when possible.
Result:
Cleaner code.
Motivation:
Right now addHandlers(first:) does not actually add handlers at the
front of the pipeline: it just adds them *backwards* at the end of
the pipeline. That's definitely not right.
Modifications:
Pass the first: flag into the call to add each specific handler to
ensure they're actually put at the front of the pipeline.
Result:
Handlers added to the front of the pipeline actually are.
Motivation:
Fix for issue #110, .description on IPv6 addresses
return a String with 0 codepoints in it, like so:
[IPv6]::1<NUL><NUL><NUL>....lots..
Modifications:
Use String(cString:) instead of decode, which doesn't
care about \0-cstr terminators.
Result:
Issue fixed, everything is awesome, everyone is happy.
Motivation:
The path of the script to invoke was wrong,
also highlight that this is absolutely required
for a PR.
Modifications:
Some bold, some text, some proper path.
Result:
CI will be super happy as less people will
fail to generate proper Linux tests.
Motivation:
prevent adding source that does not include the license header
Modifications:
add a check in sanity script to grep over all swift files and make sure they have the license header
Result:
ci build will fail if/when trying to commit source files that do not include the license header
Motivation:
It should be possible to have channels that are not registered
for any form of I/O without them getting stuck in that model
forever.
Modifications:
Remove the code that prevents channels registered for `.none` from
registering for anything else.
Result:
Channels can actually be registered for nothing without becoming
wedged open forever.
Motivation:
It's often useful for users to be able to store a thread-specific value (and so also EventLoop specific). We have ThreadSpecificVariable for this which was internal.
Modifications:
Change ThreadSpecificVariable to be public.
Result:
Fixes [#61].
Motivation:
We should use ctx.remoteAddress whenever possible as its "cheaper".
Modifications:
Replace ctx.channel.remoteAddress with ctx.remoteAddress
Result:
More correct and better example code.
Motivation:
Thread is declared final, so I believe spawnAndRun should be static.
Modifications:
Change class func to static
Result:
More consistent code, and spawnAndRun is statically dispatched.
Motivation:
We should just use one Box to store both, the local and the remote address. This will remove some heap allocations. And reduce memory overhead.
Modifications:
Use a tuple which holds the local and remote address and so only use one Box for the cached addresses.
Result:
Less heap allocations and less memory usage.
Motivation:
There are a few network protocols that are best implemented with child
`Channel`s. And given that those child `Channels` need a
`ChannelPipeline` the init for `ChannelPipeline` should be public.
Otherwise these protocols can only be sensibly implemented in the core
`NIO` module which is unfair.
Modifications:
make `ChannelPipeline.init` public
Result:
modules other than `NIO` can implement child `Channel`s.
Motivation:
repository currently contains two seperate docker definitions that are confusing to users
Modifications:
* remove Dockerfile.xenial so we have a canonical docker file for CI and developer testing
* point docker compose to canonical docker file
* define docker compose services for unit and integration tests. and make "test" service run both
* update readme
Result:
users are less confused about docker setup