thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (THRIFT-4187) Dart -> Rust Framed cross tests fail
Date Mon, 15 May 2017 15:10:04 GMT

    [ https://issues.apache.org/jira/browse/THRIFT-4187?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16010669#comment-16010669
] 

ASF GitHub Bot commented on THRIFT-4187:
----------------------------------------

Github user allengeorge commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/1269#discussion_r116516987
  
    --- Diff: lib/dart/lib/src/transport/t_framed_transport.dart ---
    @@ -51,33 +58,112 @@ class TFramedTransport extends TBufferedTransport {
           if (got > 0) return got;
         }
     
    -    _readFrame();
    +    // IMPORTANT: by the time you've got here,
    +    // an entire frame is available for reading
     
         return super.read(buffer, offset, length);
       }
     
       void _readFrame() {
    -    _transport.readAll(headerBytes, 0, headerByteCount);
    -    int size = headerBytes.buffer.asByteData().getUint32(0);
    +    if (_body == null) {
    +      bool gotFullHeader = _readFrameHeader();
    +      if (!gotFullHeader) {
    +        return;
    +      }
    +    }
    +
    +    _readFrameBody();
    +  }
    +
    +  bool _readFrameHeader() {
    +    var remainingHeaderBytes = headerByteCount - _receivedHeaderBytes;
     
    -    if (size < 0) {
    +    int got = _transport.read(_headerBytes, _receivedHeaderBytes, remainingHeaderBytes);
    +    if (got < 0) {
           throw new TTransportError(
    -          TTransportErrorType.UNKNOWN, "Read a negative frame size: $size");
    +          TTransportErrorType.UNKNOWN, "Socket closed during frame header read");
         }
     
    -    Uint8List buffer = new Uint8List(size);
    -    _transport.readAll(buffer, 0, size);
    -    _setReadBuffer(buffer);
    +    _receivedHeaderBytes += got;
    +
    +    if (_receivedHeaderBytes == headerByteCount) {
    +      int size = _headerBytes.buffer.asByteData().getUint32(0);
    +
    +      _receivedHeaderBytes = 0;
    +
    +      if (size < 0) {
    +        throw new TTransportError(
    +            TTransportErrorType.UNKNOWN, "Read a negative frame size: $size");
    +      }
    +
    +      _bodySize = size;
    +      _body = new Uint8List(_bodySize);
    +      _receivedBodyBytes = 0;
    +
    +      return true;
    +    } else {
    +      _registerForReadableBytes();
    +      return false;
    +    }
    +  }
    +
    +  void _readFrameBody() {
    +    var remainingBodyBytes = _bodySize - _receivedBodyBytes;
    +
    +    int got = _transport.read(_body, _receivedBodyBytes, remainingBodyBytes);
    +    if (got < 0) {
    +      throw new TTransportError(
    +          TTransportErrorType.UNKNOWN, "Socket closed during frame body read");
    +    }
    +
    +    _receivedBodyBytes += got;
    +
    +    if (_receivedBodyBytes == _bodySize) {
    +      var body = _body;
    +
    +      _bodySize = 0;
    +      _body = null;
    +      _receivedBodyBytes = 0;
    +
    +      _setReadBuffer(body);
    +
    +      var completer = _frameCompleter;
    +      _frameCompleter = null;
    +      completer.complete(new Object());
    --- End diff --
    
    I was a little worried about returning the frame bytes, but I guess it doesn't matter.
Also, I assume that each call to `iterator` returns a completely separate iterator with a
view to the underlying buffer.
    
    I'll change it. BTW, it's a little weird that `flush()` returns bytes...


> Dart -> Rust Framed cross tests fail
> ------------------------------------
>
>                 Key: THRIFT-4187
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4187
>             Project: Thrift
>          Issue Type: Bug
>          Components: Rust - Library
>            Reporter: Allen George
>            Assignee: Allen George
>            Priority: Minor
>
> For some reason the Dart (client) -> Rust (server) framed-transport cross tests fail.
Initial investigation shows that *somehow* the dart client think the socket was closed, which
means it doesn't read the message from the underlying transport.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message