Avoid deadlocks on OOM situations (backported patch)