Files
swift-nio/Sources
Johannes Weiß f2343bfd95 retain Channel from ChannelPipeline until destroyed (#415)
Motivation:

A long time ago, `ChannelPipeline.channel` was public and needed to be
thread-safe. That meant we could never mutate `ChannelPipeline.channel`.
Instead we stored it as an unowned reference that we only read when the
`Channel` was still alive.

It was the right call making `ChannelPipeline.channel` internal but we
forgot to then remove the `unowned` reference from `ChannelPipeline` to
`Channel`. This patch makes this reference strong but nils it out
whenever the `ChannelPipeline` is destroyed. That makes everything
easier because there is no danger anymore that the `Channel` gets
deallocated when the `ChannelPipeline` is still alive.

After destroying the `ChannelPipeline` we will still hand out a
`DeadChannel` if you call `ctx.channel` (as it's a non-optional
requirement).

This comes with an unfortunate drawback: Now if you just leak an open
Channel (which you shouldn't be able to when using the Bootstraps) we
can no longer detect that as the Channel and the ChannelPipeline will
have a retain cycle. Unfortunately I don't think there's a good way to
safely assert that.

Modifications:

- made `ChannelPipeline` hold a strong reference to `Channel` until the
  `ChannelPipeline` is destroyed

Result:

- don't crash if the user only retains the ChannelPipeline but not the
  Channel
2018-05-22 11:01:00 +02:00
..
2017-12-15 09:50:12 +00:00
2018-05-18 10:48:18 +02:00
2018-03-19 14:45:32 +01:00