[FastCgi] Use a lock to prevent race conditions