buglwIP - A Lightweight TCP/IP stack - Bugs: bug #60757, tcp_close can never fail, but its...


You are not allowed to post comments on this tracker with your current authentication level.

bug #60757: tcp_close can never fail, but its signature and documentation suggest it can

Submitted by:  Christopher Head <hawk777>
Submitted on:  Wed 09 Jun 2021 05:48:33 PM UTC  
Category:  TCP Severity:  3 - Normal
Item Group:  Change Request Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Planned Release:  2.2.0
lwIP version:  Other

Mon 04 Oct 2021 03:01:40 PM UTC, comment #1: 

Targeting 2.2.0 as this is an API change.

Simon Goldschmidt <goldsimon>
Project Administrator
Wed 09 Jun 2021 05:48:33 PM UTC, original submission:  

Version is 2.1.2; this is not available in the drop-down list.

The tcp_close() function returns an err_t, and the documentation says:

> ERR_OK if connection has been closed another err_t if closing failed and pcb is not freed


  • tcp_close always returns tcp_close_shutdown(pcb, 1)
  • tcp_close_shutdown always returns either ERR_OK or tcp_close_shutdown_fin(pcb)
  • tcp_close_shutdown_fin returns either ERR_OK or tcp_send_fin(pcb), except in the latter case, ERR_MEM is converted to ERR_OK
  • tcp_send_fin returns either ERR_OK or tcp_enqueue_flags(pcb, TCP_FIN)
  • tcp_enqueue_flags returns either ERR_OK or ERR_MEM

Therefore tcp_close can only ever return ERR_OK. Normally this wouldn’t matter much, and I would say it’s reasonable to check for errors in case future versions of lwIP need to add error returns, but tcp_close is special: closing and disposing of resources is something that’s often done in situations where recovering from an error is difficult (for example when already handling another error). It would make using lwIP more ergonomic if tcp_close were documented as never failing, which ideally would be accompanied by a change of signature to return void instead of err_t.

Christopher Head <hawk777>


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by hawk777 (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-10-04 goldsimon Planned ReleaseNone => 2.2.0

    Back to the top

    Powered by Savane 3.7