Search code examples
pharoseaside

Web page times out when using Image based persistence and saving with Seaside?


I'm using the code here to save the image when creating a new user (Persistence chapter)

saveImageWithoutMonitor

 SmalltalkImage current saveSession.


writeMutex

 ^ WriteMutex ifNil: [WriteMutex := Monitor new]

The problem is saving the image takes time and I suspect Seaside on port 8080 is inaccessible and the browser tries to request the next page and it fails to connect. Any better way to do this? Or configure Seaside to delay the page response?

PS. I remember something you had to configure it in Seaside's config page and it would wait.


Solution

  • During saving the image shutdown and startup lists will be processed during which all sockets will be destroyed, hence the connections are canceled. What we do is to fork the image (with OSProcess) and do the saving in the child process. There's even a method that will do this for you, see OSProcess>>saveImageInBackground.

    Side note: there are a couple of race conditions when using a forked process like this. If you're dealing with load, it can happen for instance that the child process "steals" the socket from the parent process, which will result in connection timeouts. To prevent this you would need to close the sockets during the fork operation which isn't an easy problem to solve.