OPEN without a timeout

objectscriptQuality release 
1.0.0
Id 
OS0056
Rule type 
Code Smell
Severity 

Blocker

Blocker
SQALE characteristic 
  • Reliability
    • Fault tolerance
Tags 
probable-bug, trap
Remediation function 
Constant/issue
Remediation cost 
1h

When you use OPEN and do not specify a timeout, as in:

    // Open a file read only
    open "myfile":("R")

then the process will block indefinitely until the resource is available.

For instance, in the example above, if myfile does not exist, the process will hang.

For this reason, you should always specify a timeout. Note that a timeout of 0 will return immediately if open fails, so in the event of files, you might want to use that, and check afterwards for the $TEST variable to check whether the open succeeded. For instance:

    // Note the 0
    open "myfile":("R"):0

    if ('$test) {
        // Oops! Open failed...
    }