-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Channel Handler that closes the channel #967
Conversation
Can one of the admins verify this patch? |
4 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
641d0d0
to
1882ae7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, generally this looks good! Do you mind addressing the notes I’ve left in the diff?
@@ -0,0 +1,11 @@ | |||
import Foundation | |||
|
|||
final public class ChannelHandlerError: ChannelInboundHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be called CloseOnErrorHandler
or something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the file names with the new handler name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually @normanmaurer is there prior art in Netty here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not include such a handler in Netty, so no :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also need to prefix this with NIO
. I.e. NIOCloseOnErrorHandler
because that's the guarantee we gave in the public API declaration.
The other question is: is this swift-nio
or swift-nio-extras
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I could go either way there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the NIO prefix, for the rest just let me know 😀
@@ -0,0 +1,11 @@ | |||
import Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import of Foundation
is unnecessary and can be removed. Additionally, you’ll need to place a license header in this file, as seen in the others.
@@ -0,0 +1,46 @@ | |||
import XCTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file also needs a license header.
@Lukasa All done, thanks for the feedback! |
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2019 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I wondered when I copy/pasted 🙈 Fixed!
Do you want me to squash into one commit since only the first matches the template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Squashing the commits would be great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
000bb52
to
b441c8a
Compare
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
final public class NIOCloseOnErrorHandler: ChannelInboundHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- sorry, super nit but Jazzy renders this as is, would you mind making it
public final
(instead offinal public
) - this needs documentation for all the
public
bits that don't come from at leastChannelInboundHandler
, ie. the class and theinit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Let me know if you want me to put more details in the docs.
b441c8a
to
6e05f6f
Compare
@normanmaurer @Lukasa Fixed! Sorry I should have pinged you! |
public init() {} | ||
|
||
public func errorCaught(context: ChannelHandlerContext, error: Error) { | ||
context.close(promise: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a question: should this forward the error on? @weissi?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lukasa I think I agree, yes, don't think this could do anything harmful. In most cases absolutely nothing will happen (because this will likely be the last handler) but in certain cases it might be better to give the user visibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, forward then close? I’m guessing the order matters here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that works!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, squashed into one commit!
63b4fc2
to
34c82c7
Compare
@Lukasa @normanmaurer all squashed and ready for another review 🦸🏻♂️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM... thanks
@swift-nio-bot test this please |
@Palleas your pull request uses windows newlines ( You might also want to fix your text editor to produce UNIX newlines |
Uh, how did that happen 🤨 I’ll fix that today! |
Motivation: Because of apple#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
2b2d67c
to
104d1ab
Compare
@swift-nio-bot test this please |
@swift-nio-bot test this please |
Motivation:
Because of #600, many users will start leaking Channels because they
don't close on error.
Modifications:
Result:
User will have access to an handler to use to automatically close
the channel in case of unhandled errors
Closes #841.