sidorares / sidorares/node-mysql2

how to appropriate close(interrupt) stream result before end event ?

Open
#664 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

mysqljs/mysql incompatibilities question
Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

as title, how to correctly interrupt stream results?
In mysqljs, I call .end(). that will trigger end event, then close stream
but in mysql2, TypeError: query.end is not a function
here is my code sample

// getConnection from pool
const query = conn.query('SELECT * FROM `table`')
    .on('result', (aRow)=>{
        // I handle one row and response to client, but if data is error or client disconnect, I need to stop res.
        // thus, i call query.end();
    })
    .on('end', ()=>{
        conn.release();
    });

I'm curiosity, query is readable stream or the other? but readable stream should not have end() method
should I call destroy() or close() preferable ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the conn.query call and its result/end handlers in the supplied example, then inspect how mysql2 exposes query results and stream interruption. Reproduce the client-disconnect or row-error case and compare destroy() and close() behavior; done means identifying the supported way to stop the query and release the connection without relying on an end event.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mysql, node.js
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.