Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Event handler leak on noData queries #31

Open
andvgal opened this issue Aug 22, 2017 · 0 comments
Open

Event handler leak on noData queries #31

andvgal opened this issue Aug 22, 2017 · 0 comments

Comments

@andvgal
Copy link

andvgal commented Aug 22, 2017

Obviously it's not the purpose of pg-cursor, but sometimes you do not know type of query in advance, but need to implement a common query execution logic.

If noData (INSERT/UPDATE/DELETE without RETURNING clause) queries are run through cursor then dangling rowDescription events are left on connection. It leads to Node,js memory leak warning.

Simple solution is to clear rowDescription on noData event, like:

  const ifNoData = () => {
    this.state = 'idle'
    this._shiftQueue()
    con.removeListener('rowDescription', onRowData)
  }
  
  const onRowData = () => {
    con.removeListener('noData', ifNoData)
  }

  if (this._conf.types) {
    this._result._getTypeParser = this._conf.types.getTypeParser
  }

  con.once('noData', ifNoData)
  con.once('rowDescription', onRowData)

However, it seems the code is not completely safe. We need to ensure that all introduced event handlers are removed upon cursor close by (error, noData, done, forced close, etc.)

@andvgal andvgal changed the title Event handler leak on noDarta queries Event handler leak on noData queries Aug 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant