Clean the resource after the flow has been executed

Could somebody throws me some light on this?

I have a database flow service to retrieve data from backend db, should I drop the dbConnection in the output pipeline after the flow has been excuted?


Hi, hYang.

This is sort of a trick question. The answer depends on your Flow.

If you are using transactions, the answer is yes. You will start your tranasactions with pub.db:connect and end them with pub.db.close or pub.db:closeAll.

If you are doing singular actions such as INSERT, UPDATE, SELECT or the like, the answer is no. In this case. you should use pub.db:execSQL. This built-in database service will self-manage the connection.

You can get more information about the built-in database services in the Built-In Service guide in your developer4/doc/ directory.

My understanding is that IS will create and reuse a connection for each http session so you theoretically don’t have to close the connection. However this causes problems if you anticipate a lot of individual sessions being created (multiple clients) where IS creates a connection for each session, or if you have stateless connections. As soon as you decide to use connection pooling (in order to limit the number of connections that IS creates for a particular db alias), you need to explicitly close your connection so that it’s put back in the pool.

This can have somewhat serious consequences as I’ve seen lots of flow services without the pub.db:close call - turning on connection pooling then requires you to edit all your db calls to add the ‘close’ service.

Will Kriski

Hi Will & Dan

Thank you very much.