Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony app stuck when getting EntityManager

I am working on an app which has the web component (visited via browser) and background task processing component, to which web component delegates some long running stuff.

I've just hit an issue when I refreshed my web browser only to find it loading indefinitely (first spotted in AJAX, but later in normal request).

It did not really look apparent but as soon as I shut down the background Symfony command which also utilizes EntityManager the browser get unblocked and proceeds with request.

My app uses RabbitMQ to store job requests which are publish by web component. The Symfony command uses the same "backbone" to create RabbitMQ consumer and take consume those jobs.

I tried, without any result:

  • Restarting Apache
  • Restating RabbitMQ
  • Purging RabbitMQ queue
  • Using different EntityManagers for web and command

I use OldSoundRabbitMqBundle (link) to facilitate communication between those two.

The web component gets stuck regardless of action being called (not related to RabbitMQ producer).

Has anyone stumbled upon similar issue?

This happens on dev box, I haven't got around giving it a spin on a production server, nor would I until I find out more about this.

like image 603
Jovan Perovic Avatar asked Nov 19 '17 23:11

Jovan Perovic


1 Answers

It would seem that I misused the locking mechanism in Postgres. Indeed the task processing component is a long-running task, but given that it is Symfony command, Doctrine connection is being established as early as possible.

Now comes the tricky part: I used the LOCK TABLE statement to lock some tables away from concurrent access (EXCLUSIVE type). Without closing the connection (not entity manager), those locks are left intact, until I restart the command (every 10th task).

This was the root cause.

I am still investigating some edge-cases, but since I moved away to advisory locking, I had no more lock-ups.

like image 128
Jovan Perovic Avatar answered Oct 19 '22 21:10

Jovan Perovic