Commit Graph

2169 Commits

Author SHA1 Message Date
David Nadoba 391ab9122c
Reduce the alloc limits for main (#2118)
The nightly builds have improved, so the alloc limits can drop slightly
2022-05-16 09:56:45 -07:00
David Nadoba 14ffe73e1b
Reduce the alloc limits of `1000_tcpconnections` for main (#2116)
The nightly builds have improved, so the alloc limits can drop slightly
2022-05-16 02:48:31 -07:00
David Nadoba 4fb931da3f
Deprecate unsafe `ChannelPipeline.context(handler:)` methods (#2109)
`ChannelHandlerContext` is not `Sendable` and can not safly be used outside of its  EventLoop.
2022-05-13 12:39:03 +02:00
David Nadoba bd4366b32c
Adopt `Sendable` for `Channel` (#2104) 2022-05-11 09:59:51 +01:00
David Nadoba 291143d83d
Adopt `Sendable` for `NIONetworkDevice` (#2103)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-10 09:01:56 -07:00
David Nadoba 54aadfaf38
Adopt `Sendable` for `NIOFileHandle.Mode` and `NIOFileHandle.Flags` (#2102)
`NIOFileHandler` and `FileRegion` are not thread-safe and can not conform to `Sendable`
2022-05-10 16:42:19 +01:00
David Nadoba 45b90b9506
Adopt `Sendable` for `SocketOptionProvider` (#2100) 2022-05-10 09:19:54 +01:00
David Nadoba dbbdabb24a
Adopt `Sendable` for Types in `ChannelOptions` Namespace (#2098)
* Adopt `Sendable` for Types in `ChannelOptions` Namespace

* mark `ChannelOption` as @preconcurrecy Sendable

and introduce `NIOPreconcurrencySendable`
2022-05-09 15:31:36 +01:00
David Nadoba 4fb6bf135b
Adopt `Sendable` for `CircularBuffer`, `MarkedCircularBuffer` and types in `NIOBSDSocket` namespace (#2097)
* Adopt `Sendable` for types in `BSDSocket` namespace

* Adopt `Sendable` for `CircularBuffer` and `MarkedCircularBuffer`

and also `Endianness`

* move `NIOSendable` into its own file and copy it over to syscall integration tests
2022-05-06 12:34:31 +01:00
David Nadoba 788ade1cc3
Adopt `Sendable` for `SocketAddress`, `AddressedEnvelope` and friends (#2096)
* Box: Sendable

* SocketAdress: Sendable and friends

* AddressEnvelop: Sendable and friends

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-04 09:33:57 -07:00
Cory Benfield ad8500b3d0
Define AsyncEmbeddedEventLoop (#2083)
Motivation

The rise of Swift concurrency has meant that a number of our APIs need
to be recontextualised as async/await capable. While generally this is a
straightforward task, any time those APIs were tested using
EmbeddedChannel we have a testing issue. Swift Concurrency requires the
use of its own cooperative thread pool, which is completely incapable of
safely interoperating with EmbeddedChannel and EmbeddedEventLoop. This
is becuase those two types "embed" into the current thread and are not
thread-safe, but our concurrency-focused APIs want to enable users to
use them from any Task.

To that end we need to develop new types that serve the needs of
EmbeddedChannel and EmbeddedEventLoop (control over I/O and task
scheduling) while remaining fully thread-safe. This is the first of a
series of patches that adds this functionality, starting with the
AsyncEmbeddedEventLoop.

Modifications

- Define AsyncEmbeddedEventLoop

Result

A required building block for AsyncEmbeddedChannel exists.

Co-authored-by: Franz Busch <privat@franz-busch.de>
2022-05-04 09:03:03 -07:00
Si Beaumont cd11cf8202
Move tests of NIOCore types from NIOPosixTests to NIOCoreTests (#2093)
* Move tests of NIOCore types from NIOPosixTests to NIOCoreTests

* fixup: LinuxTest

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: Port some test utils to not use NIOPosix

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: No swift-system, duh

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: read-write for temporary file in test helper

Signed-off-by: Si Beaumont <beaumont@apple.com>

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-04 08:14:18 -07:00
Cory Benfield b1b44ca67b
Reduce the alloc limits for main (#2095)
The nightly builds have improved, so the alloc limits can drop slightly
2022-05-04 15:49:40 +01:00
George Barnett 1a4028a96b
Remove build_podspec.sh (#2094)
Motivation:

We no longer support Cocoapods.

Modifications:

- Remove build_podspec.sh and associated scripts

Result:

Less unused code.
2022-05-04 03:19:09 -07:00
David Nadoba 5868651f58
Adopt `Sendable` for `ByteBuffer` and friends (#2092)
- `ByteBuffer`
- `ByteBufferView`
- `_ByteBufferSlice`
- `_UInt24`
- `_UInt56`
2022-05-03 08:55:23 -07:00
David Nadoba d47e96ad87
Adopt sendable in `_NIODataStructures` (#2091) 2022-05-03 05:12:37 -07:00
David Evans 71f60c4fd5
Make NIOConcurrencyHelpers Sendable (#2090)
Stop Sendable related warnings when using types defined inside NIOConcurrencyHelpers. All the code should actually already be thread safe, so no changes needed other than labelling some classes as either Sendable or @unchecked Sendable.
2022-04-28 17:04:46 +01:00
Si Beaumont 124119f0bb
BaseSocket: Remove dead code in BaseSocket.bind(to:) (#2086)
Signed-off-by: Si Beaumont <beaumont@apple.com>
2022-04-22 09:42:09 -07:00
Fabian Fett 1fbb42b245
Fix warnings, that appeared after requiring Swift 5.4 (#2085) 2022-04-21 09:12:01 -07:00
Si Beaumont 684c09315f
Use unbuffered IO for stdout in NIOPerformanceTester (#2072)
* Use unbuffered IO for stdout in NIOPerformanceTester

Signed-off-by: Si Beaumont <beaumont@apple.com>

* CRASH PERF TESTS: Up task count to 1M to test logging change

* Revert "CRASH PERF TESTS: Up task count to 1M to test logging change"

This reverts commit d8fa50eb15.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-04-20 13:16:14 -07:00
George Barnett f32314f82f
Script to list transitive dependencies (#2082)
Motivation:

Cocoapods appears to have a different idea of the dependency graph to
SPM which has led to a handful of build failures (e.g.
https://github.com/apple/swift-nio/issues/2073).

This appears to have originated when we dropped the explicit dependency
on `CNIOAtomics` from `NIO` (https://github.com/apple/swift-nio/pull/1719).

We can work around this by listing all transitive dependencies as
requirements in the generated podspecs.

Modifications:

- Add a script to list transitive dependencies for a given module.
- Fix a bug in build_podspecs.sh which did a `pod repo update` even if
  the pods were not being uploaded.
- Update build_podspecs.sh to use transitive dependencies.
- Use Python3 in 'dev/stackdiff-dtrace.py' and update soundness.sh

Result:

Podspecs should include all transitive dependencies.
2022-04-20 14:39:43 +01:00
Fabian Fett dc8a317a24
Drop support for Swift 5.2 and 5.3 (#2080)
* Drop support for 5.2 and 5.3

As outlined in a [Swift forums post in November ’21](https://forums.swift.org/t/swiftnio-swift-version-support/53232), SwiftNIO will only support the latest non-patch Swift release and the 2 immediately prior non-patch versions.

In this commit we drop support for Swift 5.2 and 5.3. We update CI for Swift 5.4 to run on bionic instead of focal to ensure that we still test bionic.

* Added Versions paragraph to Security document

* Apply suggestions from code review

Co-authored-by: Cory Benfield <lukasa@apple.com>

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-04-20 11:48:41 +01:00
Johannes Weiss ef8430d620
update contributors (#2077) 2022-04-19 16:40:26 +01:00
Johannes Weiss 5ec860a3c8
http_parser uses "main" as the main branch (#2078) 2022-04-13 22:00:29 +01:00
Cory Benfield 8f60b523b5
Remove invalid math in ByteBuffer slice slow path (#2075)
Motivation:

ByteBuffer uses a synthetic UInt24 as the lower bound of the slice of
memory that it can access. This necessitates a slow path when we create
slices of ByteBuffers that would force the lower bound to be larger than
a UInt24.

This slow path has a bunch of math within it, and it turns out that some
of it is invalid. This means in rare cases slicing a ByteBuffer can
cause a crash. That's not great: the code should only crash if we broke
an internal invariant, not because we did some invalid math.

In particular, the relevant check is calculating the upper bound of the
storage to be copied. This was:

```
min(storageRebaseAmount + _toCapacity(self._slice.count), self._slice.upperBound, storageRebaseAmount + capacity)
```

In this case, `storageRebaseAmount` is either `self._slice.lowerBound` or
`self._slice.lowerBound + self._readerIndex`: that is,
`storageRebaseAmount >= self._slice.lowerBound`. Given that
`self._slice.count == self._slice.upperBound - self._slice.lowerBound`,
we know that `storageRebaseAmount + self._slice.count` is always
strictly greater than or equal to `self._slice.upperBound`. Calculating
this is unnecessary. Unfortunately, it can also overflow: if
`self._slice.upperBound + self._readerIndex` is greater than UInt32 then
this will crash.

Note that the other math, `storageRebaseAmount + capacity`, has been
kept. `capacity` is always computed by us and this should only ever
overflow if we are increasing the size of the buffer past UInt32.max,
which we cannot handle anyway.

Modifications:

- Restructured and heavily commented _copyStorageAndRebase.
- Removed the redundant crashing check.

Result:

Less trapping!
2022-04-13 13:23:25 +01:00
Max Desiatov 564b29e103
Fix doc comment formatting in `SingleStepByteToMessageDecoder.swift` (#2076) 2022-04-12 07:17:13 -07:00
Si Beaumont 67a3b5fb17
Improve the performance of copying CircularBuffer (#2059)
* Improve the performance of copying CirularBuffer

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: Drop consuming

* fixup: whitespace

* fixup: endIndex instead of count

* fixup: Add missing self and fix test name

Signed-off-by: Si Beaumont <beaumont@apple.com>

* Avoid allocations by using @inline(__always) function

Signed-off-by: Si Beaumont <beaumont@apple.com>

* Manually inline the copy for each range

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: Linux test names after test rename

Signed-off-by: Si Beaumont <beaumont@apple.com>

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-04-04 11:58:16 +01:00
Si Beaumont 1af9615110
Increase runtime of performance tests to O(10 ms) to increase SNR (#2063)
Signed-off-by: Si Beaumont <beaumont@apple.com>
2022-03-24 07:42:24 -07:00
Cory Benfield dde891c624
Update alloc limits for nightly. (#2071)
We regressed allocs in nightly, probably for a Swift bug. Fixing it is
tracked in #2070, for now we're going to raise the limits so CI isn't
moaning all the time.
2022-03-23 10:05:11 -07:00
Franz Busch aae5fd056c
Add `Hashable` conformance to `HTTPResponseStatus` (#2069)
# Motivation
`HTTPResponseStatus` is currently not conforming to `Hashable`.

# Modification
Add `Hashable` conformance to `HTTPResponseStatus`

# Result
`HTTPResponseStatus` is `Hashable`
2022-03-23 15:39:44 +00:00
Franz Busch d6e3762e0a
Use SPM API diff checker (#2019)
### Motivation:

SPM has built in functionality to check the API of modules against a target git treeish. We can use this to simplify our `check_no_api_breakages.sh` script. Closes https://github.com/apple/swift-nio/issues/1239

### Modifications:

This PR, exchanges the direct calls to Swift's API checker with the new SPM `diagnose-api-breaking-changes` tool. This allows us to get rid of the manual module parsing, build invocations and result comparisons.

### Result:

We are now using SPMs `diagnose-api-breaking-changes` to check for breaking changes.
2022-03-22 07:41:43 -07:00
tomer doron aa631d3c8c
ci update (#2066)
motivation: 5.6 is out

changes:
* use release version of 5.6
* add docker setup for 5.7 (using nightly for now)
2022-03-16 21:28:58 -07:00
Cory Benfield d5f4a5e671
Wait a little longer for our repeated task (#2064)
Motivation:

We currently expect two runs of a repeated task in a test to happen with
relatively little breathing room: the minimum delay is 10ms, and we
won't wait longer than 50ms. We should widen this a bit.

Modifications:

- Double the deadline from 50ms to 100ms.

Result:

This test passes consistently.

Resolves #2053.
2022-03-10 02:26:56 -08:00
Cory Benfield d68066ccd7
Remove unnecessary extra swift file. (#2062)
The nightly builders have started automatically adding a struct with
@main to packages generated using swift package init. This is
interfering with our syscallwrapper tests, so we should delete that
file.
2022-03-08 08:08:47 -08:00
Cory Benfield af161d59f5
Add limits for the new test (#2060) 2022-03-08 09:22:15 +00:00
Si Beaumont be5fb3c170
Add benchmarks for copying CircularBuffer to Array (#2058)
Signed-off-by: Si Beaumont <beaumont@apple.com>

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-03-07 08:39:28 -08:00
Cory Benfield b2195f7973
Rebind less load more (#2055)
* rebind less, load more.

* Rebind even less, load even more

* Remove the mutatings

Co-authored-by: Guillaume Lessard <guillaume.lessard@apple.com>
2022-03-07 03:20:16 -08:00
BenedictSt d489d9f38f
Fixed some typos (#2051)
Fixed some typos.
2022-02-22 01:37:47 -08:00
Cory Benfield 74cba26b6f
Make all ByteBuffer methods inlinable (#2050)
Motivation:

We've held off on doing this for a while on the theory that function
calls are cheap, and we're happy to make them where there is no
particular need to specialize. Unfortunately, while this is true in
general, Swift is capable of optimizing ARC and exclusivity checking
when it can better understand what a method actually does.

Additionally, we'd hoped that cross-module-optimization would be a
useful addition here. Sadly, right now this still hasn't rolled out as a
default, and even if it had, it tends to be limited to smaller methods
and generic functions, all of which we've already annotated.

Modifications:

- Add @inlinable to essentially everything.

Result:

Better codegen around ByteBuffer.
2022-02-21 03:38:38 -08:00
Fabian Fett c74c3bbabf
[SelectableEventLoop] SR-15872; Save allocations when appending task (#2046)
* [SelectableEventLoop] SR-15872; Save allocations when appending task

* Add pr to workaround list

* Update alloc counters

* Update alloc script to include 5.6

* Update alloc counters

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-02-17 12:18:21 -08:00
Johannes Weiss 28850a539b
ELF: provide flatMapWithEventLoop and friends (#1996) (#2049) 2022-02-17 10:08:04 -08:00
Johannes Weiss a326de5a9c
atomics: make add/sub @discardableResult (#2048) 2022-02-17 08:03:12 -08:00
Fabian Fett c562f962b8
Add an allocation test for execute which needs to hop threads. (#2047)
* Add an allocation test for execute which needs to hop threads.

* Add new alloc limits for CI
2022-02-17 09:21:40 +00:00
Sebastian Vogt 154f1d3236
Implement BBV custom contains function. (#2044) 2022-02-09 13:05:28 +00:00
Stepan Ulyanin d1814ea5cf
replace the double encoding by writing bytes directly to the buffer (#2043)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-02-08 23:41:13 -08:00
Sebastian Vogt 7000510fd7
Add benchmark for BBV contains. (#1385) (#2042)
* Add ByteBufferView contains benchmark.

* Add ByteBufferView contains benchmark.

* Add ByteBufferView contains benchmark.
2022-02-08 22:06:21 -08:00
Gwynne Raskind 7ec0281c1f
`Substring.UTF8View` began implementing `Collection.withContiguousStorageIfAvailable(_:)` starting in Swift 5.3. Update `ByteBuffer.setSubstring(_:at:)` to use it to avoid a conversion to `String` in the common case. (#1975)
Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-02-07 06:24:48 -08:00
Cory Benfield 4ad4c11526
Improve the performance of copying BBV (#2039)
Motivation:

When turning a BBV into a Collection, several of the collection
algorithms can do better if you implement the semi-private
`_copyContents` hook. We can easily implement it, so we should. While
I'm here we should clean up some other bits.

Modifications:

- Implement _copyContents.
- Implement a faster `.count` for `ByteBufferView`.
- Make `ByteBuffer.capacity` `@inlinable` to reduce ARC traffic

Result:

Copying a BBV into an Array is faster.
2022-02-07 12:40:29 +00:00
Sebastian Vogt a4ad5eb54d
Allow NIOEchoClient to receive fragmented echo responses. (#2041)
* Add buffering for reading data

* Simplify channelRead in NIOEchoClient

* Remove spacing
2022-02-07 01:35:16 -08:00
David Nadoba 4f2c6a3e0b
Add `collect(upTo:) -> ByteBuffer` and variations to `AsyncSequence` (#2038) 2022-02-03 10:31:09 -08:00