bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Race in bash-4.3 'typeset'?


From: Stuart Shelton
Subject: Race in bash-4.3 'typeset'?
Date: Mon, 24 Oct 2016 23:42:53 +0100

I have some code which evals a configuration file - but before doing so 
attempts to validate the content.  It does this by taking each potential 
keyword from the file and then doing:

if typeset -p | grep -q "^declare -. ${var}$”; then

… to determine whether the keyword in question exists as a declared but unset 
variable in the script.

However, I am seeing cases where the above incorrectly fails, or where 
executing this line twice in immediate succession will fail on the first 
invocation and then succeed on the second.  This doesn’t happen every time, and 
appears to be non-deterministic: running the entire script multiple times 
sometimes results in an earlier failure, sometimes it continues succeeding for 
many iterations more.  Turning on xtrace or adding additional debug logging 
does appear to prevent the problem from occurring, unfortunately.

Sometimes, with much less regularity, the above line actually fails with:

<script name>: typeset: write error: Broken pipe

The problem I’m hitting may be specific to Ubuntu 14.04 LTS’ 
bash-4.3.11(1)-release or may only occur within a VM environment - but it looks 
as if it may be a timing-based issue or a race-condition… although putting a 
‘sleep 0.1’ before the typeset call appears to make little or no difference.

Additionally, I can’t reproduce this behaviour on bash-4.4.

Is this or anything similar a known issue with bash-4.3 which has been 
specifically fixed (and if so, is there a URL or mailing list entry which 
documents this?) or is it something which anyone else has ever come across or 
reported?

Failing this, is there any alternative to ‘typeset’ to list a variable declared 
as local to a function but which has not yet been assigned a value?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]