ID 266401 - Katana can fail to close standard file handles on exit, resulting in deadlock

Follow

Problem summary
In some cases, Katana can fail to close standard file handles when it exits, breaking the standard idiom of reading a process' output. For example:
 

import subprocessp = subprocess.Popen(['/path/to/katana', '--script', 'something.py'], stdout=subprocess.PIPE)for line in iter(p.stdout.readline, ''):  print linep.wait()
 
In some cases, the for loop will never terminate, because Katana never closes its standard output. This can happen when Katana spawns a long running process (e.g. the AttributeScript interpreter process) that inherits the standard output Katana and waits for it to terminate before itself exiting.
 
As currently implemented, the AttributeScript interpreter won't exit (and relinquish its reference to stdout) until katanaBin exits. To resolve the deadlock, the AttributeScript interpreter needs to recognise that if katanaBin becomes a zombie process (one that has exited but still has an entry in the process table as it has not yet been reaped by its parent) then it must also exit.
 

Steps to reproduce

1)  Create a subprocess using the example below:


import subprocessp = subprocess.Popen(['/path/to/katana', '--script', 'something.py'], stdout=subprocess.PIPE)for line in iter(p.stdout.readline, ''):  print linep.wait()

2) Launch Katana with the sub process, see if the script quits.

Result: Long hanging which causes deadlock

 

Workaround

Launch Katana as a separate subprocess and wait() for it to complete. This allows Attribute Script Interpreters to detect that katanaBin has exited. It costs an extra process hanging around.

This doesn't work as a 100% solution.

Reproduced by support
Katana2.5v1 - CentOS6.9
Katana2.5v7 - CentOS6.9
Katana2.6v1 - CentOS6.9
Katana2.6v3 - CentOS6.9

Expected behaviour
The script should run and then exit correctly. It should not need to wait for Katana to close before exiting.

 

Actual behaviour
The script waits, causing hanging and potential deadlock.

    We're sorry to hear that

    Please tell us why