Skip to content
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

[#2209] Allow to cancel non-flushed writes #2214

Closed
wants to merge 3 commits into from
Closed

Conversation

normanmaurer
Copy link
Member

Proposed fix for #2209

@normanmaurer
Copy link
Member Author

@trustin let me know what you think. I'm not sure yet if we really want to support cancel writes at all.

@normanmaurer
Copy link
Member Author

Beside this. i think we also need to take care of handle cancelation for other io operations like close. Somethink like call setUncancellable() and check the return value before really do the operation

@ghost
Copy link

ghost commented Feb 7, 2014

Build result for #2214 at 4ae8c33: Success

final int mask = buffer.length - 1;
while (i != unflushed && buffer[i].msg != null) {
Entry entry = buffer[i];
if (!entry.promise.setUncancellable() && entry.promise.isCancelled()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you do this in current(..) and nioBuffers()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it make more sense here as it is the point where we flush.

Am 08.02.2014 um 01:31 schrieb Trustin Lee notifications@github.com:

In transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java:

@@ -163,6 +164,19 @@ private void addCapacity() {

 void addFlush() {
     unflushed = tail;
  •    int i = flushed;
    
  •    final int mask = buffer.length - 1;
    
  •    while (i != unflushed && buffer[i].msg != null) {
    
  •        Entry entry = buffer[i];
    
  •        if (!entry.promise.setUncancellable() && entry.promise.isCancelled()) {
    
    Can't you do this in current(..)?


Reply to this email directly or view it on GitHub.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand maybe do it in current and nioBuffers would ne not a bad idea

Am 08.02.2014 um 01:31 schrieb Trustin Lee notifications@github.com:

In transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java:

@@ -163,6 +164,19 @@ private void addCapacity() {

 void addFlush() {
     unflushed = tail;
  •    int i = flushed;
    
  •    final int mask = buffer.length - 1;
    
  •    while (i != unflushed && buffer[i].msg != null) {
    
  •        Entry entry = buffer[i];
    
  •        if (!entry.promise.setUncancellable() && entry.promise.isCancelled()) {
    
    Can't you do this in current(..)?


Reply to this email directly or view it on GitHub.

@normanmaurer
Copy link
Member Author

@trustin please check again... running benchmark now

@ghost
Copy link

ghost commented Feb 8, 2014

Build result for #2214 at b518024: Success

@normanmaurer
Copy link
Member Author

No speed difference

@ghost
Copy link

ghost commented Feb 8, 2014

Build result for #2214 at 8b224cf: Success

@xfrag xfrag mentioned this pull request Feb 9, 2014
@@ -797,6 +814,13 @@ protected static void checkEOF(FileRegion region) throws IOException {
}
}

protected static boolean checkCancelled(ChannelPromise promise) {
if (!promise.setUncancellable() && promise.isCancelled()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If setUncancellable() returns false, it means the promise has been cancelled already. i.e. promise.isCancelled() is redundant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it only tells us isDone() is true. However, I'm not sure it's a good idea to continue performing the operation when the promise is done. We should probably log a warning and then discard the request probably?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2220 - with #2220 fixed, we don't need this method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented the cancellation for all outbound operations except writes so you can focus on writes. 041d37e and 96b0a94

trustin added a commit that referenced this pull request Feb 10, 2014
- Inspired by #2214
- It actually reduces the chance of trying to marking a cancelled promise as success again, which raises an IllegalStateException.
trustin added a commit that referenced this pull request Feb 10, 2014
- Inspired by #2214
- It actually reduces the chance of trying to marking a cancelled promise as success again, which raises an IllegalStateException.
trustin added a commit that referenced this pull request Feb 10, 2014
- Inspired by #2214 by @normanmaurer
- Call setUncancellable() before performing an outbound operation
- Add safeSetSuccess/Failure() and use them wherever
trustin added a commit that referenced this pull request Feb 10, 2014
- Inspired by #2214 by @normanmaurer
- Call setUncancellable() before performing an outbound operation
- Add safeSetSuccess/Failure() and use them wherever
@normanmaurer
Copy link
Member Author

@trustin please review again

@ghost
Copy link

ghost commented Feb 11, 2014

Build result for #2214 at a957f3f: Success

@trustin
Copy link
Member

trustin commented Feb 11, 2014

LGTM. Please merge.

@normanmaurer
Copy link
Member Author

@trustin cherry-picked into 4.0 and master

@normanmaurer normanmaurer added this to the 4.0.16.Final milestone Feb 11, 2014
@normanmaurer normanmaurer deleted the cancel_writes branch March 12, 2014 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants