the connection.close function was only waiting for synchronous calls to complete, async calls that were waiting (after a synchronous) were still discarded, this has been fixed