The error leaks out from try/catch
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
Because canceling a request after a certain time is impossible (technically difficult to implement), so I'm trying to arrange a request race with a timer and if the timer is triggered earlier, we return undefined, otherwise the result of the request
const QUERY_TIMEOUT = 'query_timeout';
function sleep(ms) => new Promise((r) => setTimeout(() => r(QUERY_TIMEOUT), ms));
async function execQuery() {
try {
const query = sql`select * from func()`; // responds in 6 seconds SELECT pg_sleep(6);
const response = await Promise.race([sleep(1000), query]);
if (response === QUERY_TIMEOUT) {
return;
} else {
return response
}
} catch(error) {
console.log('PG error:', error);
}
}
const data = await execQuery();
and in the database, a limit was set on the execution time of the statement
set statement_timeout = 5000
execute the code and get the error after getting the result from db:
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '00000',
message: 'exception:\n' +
' \tmessage: query has no destination for result data\n' +
' \tstate : 42601\n' +
' \tdetail : \n' +
' \thint : If you want to discard the results of a SELECT, use PERFORM instead.\n' +
' \tcontext: \n' +
'<NULL>',
where: 'PL/pgSQL function func() line 5 at RAISE',
file: 'pl_exec.c',
line: '3893',
routine: 'exec_stmt_raise'
}
Although it should not get errors at all because there has already been a return from this section of the code
In extreme cases, the code in the catch block should work and display an error in the log
PG error: query has no destination for result data
how is it defined in my code above
how to avoid the occurrence of an uncontrolled exception?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named. Start by reproducing the shown JavaScript Promise.race with the PostgreSQL function and statement_timeout, then review the issue discussion to determine whether the late error indicates a library bug or expected behavior; done means the behavior and any actionable change are clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100