Subject Spurious "unable to allocate memory from operating system" errors
Author Wendel Schaatsbergen
Note: reposted from the firebird-support list.

Hi all,

Problem synopsis:

When committing transactions with BLOBs in many threads, using Hibernate and Jaybird, I'm getting spurious memory exceptions from the Firebird driver.

My setup:

I have a web application that runs with the following installation:
- Windows 7
- Firebird 2.5 Super Server
- JDK 1.6.0
- Jaybird 2.1.6
- Hibernate 3.5.6
- Tomcat 6.0

I'm using the standard firebird.conf file of the super server installation.

Problem details:

I have a daemon task which at certain times spawns many tasks that load a BLOB, does calculations on it, and stores the result either in a new row in another table, or it saves back a changed version of the original BLOB. The tasks correctly commit the transactions and close the hibernate session.

After some time of correctly committing the transactions, the tasks start to give the following exception:

org.hibernate.exception.GenericJDBCException: could not execute query using scroll
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.scroll(Loader.java:2557)
at org.hibernate.loader.hql.QueryLoader.scroll(QueryLoader.java:514)
at org.hibernate.hql.ast.QueryTranslatorImpl.scroll(QueryTranslatorImpl.java:415)
at org.hibernate.engine.query.HQLQueryPlan.performScroll(HQLQueryPlan.java:269)
at org.hibernate.impl.SessionImpl.scroll(SessionImpl.java:1343)
at org.hibernate.impl.QueryImpl.scroll(QueryImpl.java:90)
at org.hibernate.impl.QueryImpl.scroll(QueryImpl.java:80)
at ch.gutermann.zonescan.server.correlation.NSquareCorrelationJob.startMonthlyAveragingTasks(Unknown Source)
at ch.gutermann.zonescan.server.correlation.NSquareCorrelationJob.startCorrelations(Unknown Source)
at ch.gutermann.zonescan.server.correlation.NSquareCorrelationJob.execute(Unknown Source)
at org.quartz.core.JobRunShell.run(JobRunShell.java:199)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544676. sort error: not enough memory
at org.firebirdsql.jdbc.AbstractPreparedStatement.internalExecute(AbstractPreparedStatement.java:730)
at org.firebirdsql.jdbc.AbstractPreparedStatement.executeQuery(AbstractPreparedStatement.java:165)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1869)
at org.hibernate.loader.Loader.scroll(Loader.java:2522)
... 11 more

When this happens, every subsequent task will give the same error, "unable to allocate memory from operating system". However, when I wait several minutes and then start the tasks again, the tasks will run correctly again for some time, potentially starting to give the error again later on.

Has anybody had similar problems involving multithreaded transaction with many BLOBs? Is there anything I could do to fix or work around this problem?

Thanks for any help!

Bye,
Wendel Schaatsbergen