Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5125

Swift server does not work using present code.



    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.14.0
    • 0.14.0
    • Swift - Library
    • None


      TL;DR: Swift server does not work using present code.


      I'm writing thrift server in swift running on iOS. For reference, I'm using SocketServer, MultiplexedProcessor with BinaryProtocol over FramedTransport. Client is in Java, and we already have Java server running on Android.

      Note that I'm new to swift, iOS and Apple world, so I may not understand everything.


      During development I've found these issues:


      1. TSocketServer.init(): Conversion of port: Int to sin_port: in_port_t (that is UInt16) fails with "... is not representable as...". UInt16(truncatingIfNeeded: ).bigEndian is needed instead of port.bigEndian
      2. https://github.com/apache/thrift/blob/master/lib/swift/Sources/TSocketServer.swift#L85 tries to deallocate address, due to nil deallocator, equivalent to kCFAllocatorDefault. Proper deallocator seems to be kCFAllocatorNone.
      3. According to https://developer.apple.com/documentation/foundation/nsfilehandle/1413309-acceptconnectioninbackgroundandn?language=objc (see last paragraph), socketFileHandle.acceptConnectionInBackgroundAndNotify() should be called again at the end of TSocketServer.connectionAccepted(). Old cocoa code does it.
      4. TSocketServer.connectionAccepted() tries to read from the listening socket instead of client socket, resulting in "Socket not connected" error. Client socket handle is in notification.userInfo[NSFileHandleNotificationFileHandleItem]
      5. TSocketServer.handleClientConnection handles only one message. Loop is missing around try processor.process(). I.e. while true { try processor.process }
      6. It is not possible to pass TFramedTransport to TSocketServer
      7. TSocketServer.serviceHandle is not used anymore
      8. FileHandle.acceptConnectionInBackgroundAndNotify() is not implemented in Linux swift 4.2. Upgrade to 5.1 is required for this to work on Linux. See  https://github.com/apple/swift-corelibs-foundation/commit/fc96d7fd139bc894689b5cc13a22d9c52424caf8 Cross tests can't work with 4.2.

      PR with fixes: https://github.com/apache/thrift/pull/2038


      • Before merging this I suggest merging PR 2036
      • I did not create tests for connection changes. I could not get client and server work in the same process/thread. I will try to write simple test to check the code in cross tests but that may take some time.
      • I've tried to create test for socketserver, but could not implement client connect problem with Int to UInt16 is most probably present in client code as well (TSocketTransport)
      • I've created separate issue THRIFT-5128 for TFramedTransport problems, to keep this one manageable.


        Issue Links



              janosvitok Jano Svitok
              janosvitok Jano Svitok
              0 Vote for this issue
              0 Start watching this issue



                Time Tracking

                  Original Estimate - Not Specified
                  Not Specified
                  Remaining Estimate - 0h
                  Time Spent - 0.5h