helpThe GNU Bourne-Again SHell - Support: sr #109608, Read timeout in trap of a read...


sr #109608: Read timeout in trap of a read with a timeout leads to stuck script

Submitter:  None
Submitted:  Wed 26 Dec 2018 08:17:15 AM UTC
Category:  None Priority:  5 - Normal
Severity:  2 - Minor Status:  Done
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Wed 26 Dec 2018 03:53:28 PM UTC, comment #1: 

Bash uses real-time interval timers to implement read timeouts (the ones that deliver SIGALRM when they expire). A process can only have one itimer at a time; the one started by the trap command overwrites the previous one.

Chet Ramey <chet>
Project Administrator
Wed 26 Dec 2018 08:17:15 AM UTC, original submission:  

GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)

When reading with a timeout in a trap that is trapping a read  with a timeout, the original read never times out.

The following script will reproduce the behavior.

    read -t2 -ru ${fd} line
    echo $line

    echo trapped

trap 'echo terminated; exit 2' SIGTERM
trap 'trap_int' SIGINT

exec {fd}< <(msg_trap)
read  -t10 line

echo "res $?line: $line"


The script never ends, the read in the main function will no longer time out.
The bug can be worked around by doing a read -t0 first in the trap.
When the read in the trap function has no time out it also works.



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

Attach Files:

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 chet (Posted a comment)
  • -email is unavailable- added by None (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.

    Only logged-in users can vote.





    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-26 chet StatusNone Done

    Back to the top

    Powered by Savane 3.10