Skip to content

Commit

Permalink
Fixed issue where arc.tables could keep Sandbox Dynamo connections …
Browse files Browse the repository at this point in the history
…open for 5s in Node 18+

Update deps and changelog
  • Loading branch information
ryanblock committed Jun 13, 2023
1 parent d8c6ddd commit f80010f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@
"@architect/asap": "^5.1.1",
"@architect/eslint-config": "2.0.1",
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
"@architect/sandbox": "^5.5.4",
"@architect/sandbox": "^5.6.8",
"@aws-sdk/client-apigatewaymanagementapi": "^3.319.0",
"@aws-sdk/client-dynamodb": "^3.319.0",
"@aws-sdk/client-sns": "^3.319.0",
"@aws-sdk/client-sqs": "^3.319.0",
"@aws-sdk/client-ssm": "^3.319.0",
"@aws-sdk/lib-dynamodb": "^3.319.0",
"@aws-sdk/node-http-handler": "^3.347.0",
"@types/aws-lambda": "^8.10.114",
"@types/node": "^18.15.11",
"aws-sdk": "^2.1364.0",
"cross-env": "~7.0.3",
"eslint": "^8.39.0",
"eslint": "^8.42.0",
"mock-fs": "~5.2.0",
"nyc": "~15.1.0",
"proxyquire": "~2.1.3",
"sinon": "^15.0.3",
"sinon": "^15.1.0",
"tap-spec": "~5.0.0",
"tape": "~5.6.3",
"tiny-json-http": "^7.5.1",
Expand Down
30 changes: 21 additions & 9 deletions src/tables/dynamo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
let https = require('https')
let { getPorts, isNode18, useAWS } = require('../lib')

/**
Expand Down Expand Up @@ -35,16 +34,21 @@ function getDynamo (type, callback) {
}

if (useAWS()) {
let config = {
httpOptions: {
agent: new https.Agent({
keepAlive: true,
maxSockets: 50, // Node can set to Infinity; AWS maxes at 50
rejectUnauthorized: true,
})
let config
// SDK v2 (Node <=16) does not have keep-alive enabled by default, whereas v3 (>=18) does
if (!isNode18) {
let https = require('https')
config = {
httpOptions: {
agent: new https.Agent({
keepAlive: true,
maxSockets: 50, // Node can set to Infinity; AWS maxes at 50
rejectUnauthorized: true,
})
}
}
}
db = isNode18 ? new DB : new DB(config)
db = new DB(config)
doc = isNode18 ? Doc.from(db) : new Doc(config)
return callback(null, type === 'db' ? db : doc)
}
Expand All @@ -60,6 +64,14 @@ function getDynamo (type, callback) {
endpoint: `http://localhost:${port}`,
region: AWS_REGION || 'us-west-2' // Do not assume region is set!
}
if (isNode18) {
// Disable keep-alive locally (or wait Node's default 5s for sockets to time out)
let http = require('http')
let { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
config.requestHandler = new NodeHttpHandler({
httpAgent: new http.Agent({ keepAlive: false })
})
}
db = new DB(config)
doc = isNode18 ? Doc.from(db) : new Doc(config)
return callback(null, type === 'db' ? db : doc)
Expand Down

0 comments on commit f80010f

Please sign in to comment.