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

Submitter:  Christopher Head <hawk777>
Submitted:  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.3.0
lwIP version:  Other

Thu 22 Dec 2022 09:01:23 PM UTC, comment #2: 

retargeting to 2.3.0

Simon Goldschmidt <goldsimon>
Group administrator
Mon 04 Oct 2021 03:01:40 PM UTC, comment #1: 

Targeting 2.2.0 as this is an API change.

Simon Goldschmidt <goldsimon>
Group 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>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

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)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-12-22 goldsimon Planned Release2.2.0 2.3.0
    2021-10-04 goldsimon Planned ReleaseNone 2.2.0

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code