Allow me to understand the scenario here.
Are you doing recording like this?
1.) pullstream uri=<address of stream source> localStreamName=s1
2.) record localStreamName=s1 pathtofile=<somedir> type=mp4
N.) shutdownStream id=<record id>
Is the above steps similar to what you are doing? If not, please show us your work flow?