I have a dialplan setup that records a bridged call in FreeSWITCH, which sets the 'api_hangup_hook' variable to call a lua script when the call hangs up, and the called lua script moves the recorded .wav file from it's temporary location to a final destination.
This works, but recently I noticed that some of my .wav recordings have no header information, which results in many players choking when trying to play it.
I eventually figured out that the header information for the .wav file appears to be written *after* the call is hung up, and file move operation in the api_hangup_hook moves the file before the header information has been written. This occurs sporadically.
I've found that introducing a 1 second sleep in my lua script fixes this race condition, but that seems a bit of an ugly hack.
Curious if anybody else has run into this, and/or can offer me a cleaner solution than my sleep hack.
I'm attaching a brief summary of the dialplan and lua script for anyone that wants to see the code.
_________________________________________________________________________