You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Tim Wilson-Brown (JIRA)" <ji...@apache.org> on 2010/04/01 13:40:27 UTC

[jira] Created: (THRIFT-749) C++ TBufferedTransports do not close the underlying connection on delete

C++ TBufferedTransports do not close the underlying connection on delete
------------------------------------------------------------------------

                 Key: THRIFT-749
                 URL: https://issues.apache.org/jira/browse/THRIFT-749
             Project: Thrift
          Issue Type: Bug
          Components: Library (C++)
    Affects Versions: 0.2, 0.3
         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
            Reporter: Tim Wilson-Brown
            Priority: Trivial


The C++ TBufferedTransports (such as TBufferedTransport) do not close the underlying connection on delete.

The workaround is to manually close the TBufferedTransport (which does close the underlying connection) before deleting it.

This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "Tim Wilson-Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Wilson-Brown reopened THRIFT-749:
-------------------------------------


Sorry, I didn't see Adam's and David's comments about discarding the data in wBuf_ when I closed this bug.

At the very least, we should document (& fix where necessary) buffered transport behaviour.
The options for Buffered Transports are:
  * flush in destructor - likely to throw exceptions in destructor
  * write in destructor - can throw exceptions in destructor
  * discard data in wBuf_ - no guarantee that data is written to underlying transport
    - (but thrift processors currently have an explicit flush after every message)

Whatever option is chosen, we can implement Adam's suggestion that "callers should still be encouraged to explicitly call flush() before destroying any transport."

I can't see a way to guarantee that we don't throw exceptions in destructors, and guarantee that we write out all the buffered data.
How do other C++ networking libraries do it?

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "Tim Wilson-Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852705#action_12852705 ] 

Tim Wilson-Brown commented on THRIFT-749:
-----------------------------------------

In the generated code I have from Thrift r760184, the sequence is:

  oprot_->writeMessageEnd();
  oprot_->getTransport()->flush();
  oprot_->getTransport()->writeEnd();

writeEnd() is a no-op in most transports, but where it is implemented (TPipedTransport), it does its own flush.

I wasn't aware of the flush in the processor - sorry for taking up your time.

There is no compelling issue - this was one potential cause of some issues I'm having with Thrift and fork.
The proven causes are [THRIFT-747] and [THRIFT-748].

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "Adam Simpkins (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852672#action_12852672 ] 

Adam Simpkins commented on THRIFT-749:
--------------------------------------

Yeah, that probably should be fixed.  The processor code explicitly calls flush() on the transport after writing each message, which is why we haven't seen any issues because of this so far.

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "Tim Wilson-Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852705#action_12852705 ] 

Tim Wilson-Brown edited comment on THRIFT-749 at 4/2/10 4:50 AM:
-----------------------------------------------------------------

In the generated code I have from Thrift r760184, the sequence is:

  oprot_->writeMessageEnd();
  oprot_->getTransport() ->flush();
  oprot_->getTransport() ->writeEnd();

writeEnd() is a no-op in most transports, but where it is implemented (TPipedTransport), it does its own flush.

I wasn't aware of the flush in the processor - sorry for taking up your time.

There is no compelling issue - this was one potential cause of some issues I'm having with Thrift and fork.
The proven causes are [THRIFT-747] and [THRIFT-748].

      was (Author: twilsonb):
    In the generated code I have from Thrift r760184, the sequence is:

  oprot_->writeMessageEnd();
  oprot_->getTransport()->flush();
  oprot_->getTransport()->writeEnd();

writeEnd() is a no-op in most transports, but where it is implemented (TPipedTransport), it does its own flush.

I wasn't aware of the flush in the processor - sorry for taking up your time.

There is no compelling issue - this was one potential cause of some issues I'm having with Thrift and fork.
The proven causes are [THRIFT-747] and [THRIFT-748].
  
> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "Tim Wilson-Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Wilson-Brown closed THRIFT-749.
-----------------------------------

    Resolution: Not A Problem

This issue is not a problem as long as processors call flush in writes.

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-749) C++ TBufferedTransports do not close the underlying connection on delete

Posted by "Adam Simpkins (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852481#action_12852481 ] 

Adam Simpkins commented on THRIFT-749:
--------------------------------------

If you have a TBufferedTransport that wraps a TSocket, the TSocket should still close itself when it gets destroyed.

The TBufferedTransport contains a shared_ptr to the underlying transport.  If the underlying transport is not destroyed when the TBufferedTransport is destroyed, this must mean another location in your code is still holding on to a shared_ptr for the underlying transport.  In this situation, it makes sense not to close it, that other location in the code may still be using it.

> C++ TBufferedTransports do not close the underlying connection on delete
> ------------------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> The C++ TBufferedTransports (such as TBufferedTransport) do not close the underlying connection on delete.
> The workaround is to manually close the TBufferedTransport (which does close the underlying connection) before deleting it.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "David Reiss (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852718#action_12852718 ] 

David Reiss commented on THRIFT-749:
------------------------------------

I actually have an upcoming diff that reorders flush and writeEnd.

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "David Reiss (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852702#action_12852702 ] 

David Reiss commented on THRIFT-749:
------------------------------------

What's the problem with not guaranteeing that wBuf_ data is sent on to the underlying transport without an explicit flush?

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "David Reiss (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852677#action_12852677 ] 

David Reiss commented on THRIFT-749:
------------------------------------

I'd prefer not to make this change unless there is a compelling case for it.  flush is an operation that can easily throw an exception, and it's best to avoid throwing exceptions from destructors.  What is the problem with requiring and explicit flush?

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "Tim Wilson-Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Wilson-Brown updated THRIFT-749:
------------------------------------

    Description: 
Edit: replaced 'close underlying transport' with 'flush buffers'

The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.

The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.

This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
Data may be buffered then lost when the TBufferedTransport is deleted.
This is undesirable  - they should behave identically except for the buffering.

  was:
The C++ TBufferedTransports (such as TBufferedTransport) do not close the underlying connection on delete.

The workaround is to manually close the TBufferedTransport (which does close the underlying connection) before deleting it.

This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
This is undesirable  - they should behave identically except for the buffering.

        Summary: C++ TBufferedTransports do not flush their buffers on delete  (was: C++ TBufferedTransports do not close the underlying connection on delete)

I understand the behaviour better now - I'm still getting used to shared_ptr.
However, AFAICT the lack of a flush() on delete is still an issue - so I've updated the title and description.

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-749) C++ TBufferedTransports do not flush their buffers on delete

Posted by "Adam Simpkins (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852698#action_12852698 ] 

Adam Simpkins commented on THRIFT-749:
--------------------------------------

Simply discarding the data in wBuf_ seems like a bug, and worse than attempting
to flush it and possibly raising an exception.

It seems like the TBufferedTransport and TFramedTransport destructors should
write out any unflushed data in their buffers, but not call flush() on the
underlying transport.  (The underlying transport should eventually flush the
data before it is closed, and calling flush() here just adds unnecessary cost.)

Callers should still be encouraged to explicitly call flush() before destroying
any transport.  If they do so, the destructor still will never throw an
exception.

> C++ TBufferedTransports do not flush their buffers on delete
> ------------------------------------------------------------
>
>                 Key: THRIFT-749
>                 URL: https://issues.apache.org/jira/browse/THRIFT-749
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>    Affects Versions: 0.2, 0.3
>         Environment: Cygwin 1.7.1 on Windows XP SP3, Thrift 0.2.0 & r760184 & Trunk 
>            Reporter: Tim Wilson-Brown
>            Priority: Trivial
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Edit: replaced 'close underlying transport' with 'flush buffers'
> The C++ TBufferedTransports (such as TBufferedTransport) do not flush their buffers on delete.
> The workaround is to manually flush the TBufferedTransport before deleting it. If the TBufferedTransport owned the last instance of the underlying transport, it will be deleted and close itself.
> This may be worth fixing - at the moment, substituting a buffered TSocket for an unbuffered one changes the behaviour on delete.
> Data may be buffered then lost when the TBufferedTransport is deleted.
> This is undesirable  - they should behave identically except for the buffering.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.