Gitlab Runner stuck after receiving exception from the server

I have prepared script that deploy changes to the server. Generally it works, but the problem appears when deploy server returns exception / error. For example, when it run following command:

ssh -o StrictHostKeyChecking=no root@example.com "cd public_html/example.com && git checkout master && git pull origin master && exit 0"

sometimes it cause the error:

fatal: mmap failed: Cannot allocate memory

It is shared hosting, so probably this is the reason for memory problem. After receiving this error, runner can’t finish the job and stuck. I even set the timeout, but it doesn’t work, and the only option which I know is restart the runner (by command-line).

Is there a way to handle errors like this and finish the job with error status?