Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1450

ftp:open/2 may kill calling process after returning error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 21.3, 22.3, 24.0, 23.1.1
    • Fix Version/s: OTP-24.0
    • Component/s: None
    • Labels:
      None

      Description

      When ftp:open/2 connects to an FTP server that doesn't respond in time, it first returns an error as expected, but soon thereafter the process that called ftp:open/2 is KILLED with reason timeout, due to ftp:open/2 linking it to a temporary gen_server that decides to exit with reason timeout.

      The attached test case reproduces the issue with every OTP release from OTP-21 to current master.

      In our case, we have to upload files to clients' FTP sites, and some of those clients have FTP servers with various levels of breakage. Usually we can detect the errors and move on, but in the cases described here, the upload process is killed unexpectedly, causing our job scheduler to halt that activity (as per its design).

      Erlang/OTP 24 [DEVELOPMENT] [erts-11.1.5] [source-13f50a0984] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
      
      Eshell V11.1.5  (abort with ^G)
      1> badftp:doit().
      badftp: server: listening on port 33673
      badftp: client: pid=<0.83.0>
      badftp: client: connecting to port 33673
      badftp: server: accept success
      badftp: client: ftp:open/2 failure: eclosed
      badftp: server: recv failure: closed
      =ERROR REPORT==== 22-Dec-2020::11:11:17.528438 ===
      Ftp connection closed due to: timeout
      
      =ERROR REPORT==== 22-Dec-2020::11:11:17.531463 ===
      ** Generic server <0.84.0> terminating 
      ** Last message in was timeout
      ** When Server state == {state,{tcp,#Port<0.7>},
                                     undefined,undefined,true,"/tmp/otp",
                                     ftp_server_default,false,passive,10000,<<>>,
                                     {<<>>,[],start},
                                     [],<0.83.0>,
                                     {<0.83.0>,#Ref<0.2972721862.3205496834.98711>},
                                     open,inet,[],[],[],ignore,10000,false,false,
                                     false}
      ** Reason for termination ==
      ** timeout
      
      badftp: client: killed: timeout
      =CRASH REPORT==== 22-Dec-2020::11:11:17.531912 ===
        crasher:
          initial call: ftp:init/1
          pid: <0.84.0>
          registered_name: []
          exception exit: timeout
            in function  gen_server:handle_common_reply/8 (gen_server.erl, line 814)
          ancestors: [<0.83.0>]
          message_queue_len: 0
          messages: []
          links: [<0.83.0>]
          dictionary: []
          trap_exit: true
          status: running
          heap_size: 2586
          stack_size: 29
          reductions: 8071
        neighbours:
          neighbour:
            pid: <0.83.0>
            registered_name: []
            initial_call: {erlang,apply,2}
            current_function: {timer,sleep,1}
            ancestors: []
            message_queue_len: 0
            links: [<0.84.0>]
            trap_exit: false
            status: waiting
            heap_size: 376
            stack_size: 4
            reductions: 213
            current_stacktrace: [{timer,sleep,1,[{file,"timer.erl"},{line,152}]},
                        {badftp,client_does_other_work,0,
                                [{file,"../badftp.erl"},{line,59}]},
                        {badftp,'-client/1-fun-0-',1,
                                [{file,"../badftp.erl"},{line,27}]}]
      {error,{exit,timeout}}
      

        Attachments

          Activity

            People

            Assignee:
            otp_team_ps Team PS
            Reporter:
            Mikael Pettersson Mikael Pettersson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: