Open
Description
In local development, when I type a longer string in main search like 'represent', the results don't load and then after ~5s, there the request to http://localhost:8082/api/search?searchText=represent
fails with 500
{"errorCode":"UNEXPECTED_ERROR"}
. In the API logs I see:
2023-04-04T15:22:32.319Z error [clientRequestId=cf91f885-839c-4633-9a8a-70450a02fe50; serverRequestId=e7af658d-a738-4339-bea1-d4840b248c54] Unexpected error {
err: Error: timeout exceeded when trying to connect
at Timeout._onTimeout (/Users/transverna/code/github/Howdju/howdju/node_modules/pg-pool/index.js:195:27)
From previous event:
at promisify (/Users/transverna/code/github/Howdju/howdju/node_modules/pg-pool/index.js:39:18)
at BoundPool.query (/Users/transverna/code/github/Howdju/howdju/node_modules/pg-pool/index.js:347:22)
at Database.query (/Users/transverna/code/github/Howdju/howdju/howdju-service-common/lib/database/Database.ts:47:22)
at TagsDao.readTagsLikeName (/Users/transverna/code/github/Howdju/howdju/howdju-service-common/lib/daos/TagsDao.js:49:8)
at TagsService.readTagsLikeTagName (/Users/transverna/code/github/Howdju/howdju/howdju-service-common/lib/services/TagsService.js:39:25)
at MainSearchService.search (/Users/transverna/code/github/Howdju/howdju/howdju-service-common/lib/services/MainSearchService.js:35:30)
at Object.handler (/Users/transverna/code/github/Howdju/howdju/howdju-service-routes/lib/routes.ts:143:61)
at routeRequest (/Users/transverna/code/github/Howdju/howdju/premiser-api/src/router.ts:73:42)
at handler2 (/Users/transverna/code/github/Howdju/howdju/premiser-api/src/handler.ts:76:12)
at Timeout._onTimeout (/Users/transverna/code/github/Howdju/howdju/premiser-api/local-server.js:58:11)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7),
stack: 'Error: timeout exceeded when trying to connect\n' +
' at Timeout._onTimeout (/Users/transverna/code/github/Howdju/howdju/node_modules/pg-pool/index.js:195:27)\n' +
'From previous event:\n' +
' at promisify (/Users/transverna/code/github/Howdju/howdju/node_modules/pg-pool/index.js:39:18)\n' +
' at BoundPool.query (/Users/transverna/code/github/Howdju/howdju/node_modules/pg-pool/index.js:347:22)\n' +
' at Database.query (/Users/transverna/code/github/Howdju/howdju/howdju-service-common/lib/database/Database.ts:47:22)\n' +
' at TagsDao.readTagsLikeName (/Users/transverna/code/github/Howdju/howdju/howdju-service-common/lib/daos/TagsDao.js:49:8)\n' +
' at TagsService.readTagsLikeTagName (/Users/transverna/code/github/Howdju/howdju/howdju-service-common/lib/services/TagsService.js:39:25)\n' +
' at MainSearchService.search (/Users/transverna/code/github/Howdju/howdju/howdju-service-common/lib/services/MainSearchService.js:35:30)\n' +
' at Object.handler (/Users/transverna/code/github/Howdju/howdju/howdju-service-routes/lib/routes.ts:143:61)\n' +
' at routeRequest (/Users/transverna/code/github/Howdju/howdju/premiser-api/src/router.ts:73:42)\n' +
' at handler2 (/Users/transverna/code/github/Howdju/howdju/premiser-api/src/handler.ts:76:12)\n' +
' at Timeout._onTimeout (/Users/transverna/code/github/Howdju/howdju/premiser-api/local-server.js:58:11)\n' +
' at listOnTimeout (internal/timers.js:557:17)\n' +
' at processTimers (internal/timers.js:500:7)'
}
2023-04-04T15:22:32.321Z debug [clientRequestId=cf91f885-839c-4633-9a8a-70450a02fe50; serverRequestId=e7af658d-a738-4339-bea1-d4840b248c54] Result status code { statusCode: 500 }
2023-04-04T15:22:32.321Z silly [clientRequestId=cf91f885-839c-4633-9a8a-70450a02fe50; serverRequestId=e7af658d-a738-4339-bea1-d4840b248c54] Result {
response: {
statusCode: 500,
headers: {
'Access-Control-Allow-Origin': 'http://localhost:3000',
'Access-Control-Allow-Headers': 'Authorization,Content-Encoding,Content-Type,sentry-trace,Request-ID,Session-Storage-ID,Page-Load-ID',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE',
'Cache-Control': 'no-cache, no-store, must-revalidate',
Expires: '0',
Pragma: 'no-cache',
Vary: 'Origin',
'Content-Type': 'application/json'
},
body: '{"errorCode":"UNEXPECTED_ERROR"}'
}
}
GET /api/search?searchText=represent 500 14649.349 ms - 32
This could be a performance issue and could support DOS attempts. We might need to support continuation, if we add a limit. We should weigh improvements against using a search platform like Elasticsearch.