Skip to content

Commit

Permalink
Up sizes & timeouts (#610)
Browse files Browse the repository at this point in the history
* Up server timeouts and max sizes

* Up file sizes and timeouts and pipe out file size errors back to client

* Fix file reference;
  • Loading branch information
raymondjacobson committed Jul 3, 2020
1 parent f2cdccd commit 1cfc3a6
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion creator-node/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"rateLimitingMetadataReqLimit": 3000,
"rateLimitingImageReqLimit": 6000,
"rateLimitingTrackReqLimit": 6000,
"maxAudioFileSizeBytes":250000000,
"maxAudioFileSizeBytes":1000000000,
"maxMemoryFileSizeBytes":50000000,
"serviceLatitude": "",
"serviceLongitude": "",
Expand Down
2 changes: 1 addition & 1 deletion creator-node/docker-compose/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rateLimitingUserReqLimit=3000
rateLimitingMetadataReqLimit=3000
rateLimitingImageReqLimit=6000
rateLimitingTrackReqLimit=6000
maxAudioFileSizeBytes=250000000
maxAudioFileSizeBytes=1000000000
maxMemoryFileSizeBytes=50000000
serviceLatitude=
serviceLongitude=
Expand Down
5 changes: 2 additions & 3 deletions creator-node/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const { userReqLimiter, trackReqLimiter, audiusUserReqLimiter, metadataReqLimite
const redisClient = require('./redis')
const config = require('./config')

const TWENTY_MINUTES = 1000 * 60 * 20 // 1,200,000ms = 20min

const app = express()
// middleware functions will be run in order they are added to the app below
// - loggingMiddleware must be first to ensure proper error handling
Expand Down Expand Up @@ -55,7 +53,8 @@ const initializeApp = (port, storageDir, ipfsAPI, audiusLibs, blacklistManager,
const server = app.listen(port, () => logger.info(`Listening on port ${port}...`))

// Increase from 2min default to accommodate long-lived requests.
server.setTimeout(TWENTY_MINUTES)
server.setTimeout(config.get('setTimeout'))
server.timeout = config.get('timeout')
server.keepAliveTimeout = config.get('keepAliveTimeout')
server.headersTimeout = config.get('headersTimeout')

Expand Down
30 changes: 27 additions & 3 deletions creator-node/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,41 @@ const config = convict({
env: 'port',
default: null
},
setTimeout: {
doc: `
Sets the timeout value (in ms) for sockets
https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_settimeout_msecs_callback
`,
format: 'nat',
env: 'timeout',
default: 60 * 60 * 1000 // 1 hour
},
timeout: {
doc: `
Sets the timeout value (in ms) for socket inactivity
https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_timeout
`,
format: 'nat',
env: 'timeout',
default: 60 * 60 * 1000 // 1 hour
},
keepAliveTimeout: {
doc: 'Server keep alive timeout',
doc: `
Server keep alive timeout
https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_keepalivetimeout
`,
format: 'nat',
env: 'keepAliveTimeout',
default: 5000 // node.js default value
},
headersTimeout: {
doc: 'Server headers timeout',
doc: `
Server headers timeout
https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_headerstimeout
`,
format: 'nat',
env: 'headersTimeout',
default: 60000 // node.js default value
default: 60 * 1000 // 60s - node.js default value
},
logLevel: {
doc: 'Log level',
Expand Down
14 changes: 13 additions & 1 deletion creator-node/src/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ const trackFileUpload = multer({
}
})

const handleTrackContentUpload = (req, res, next) => {
trackFileUpload.single('file')(req, res, (err) => {
if (err) {
if (err.code === 'LIMIT_FILE_SIZE') {
req.fileSizeError = err
}
}
next()
})
}

function getFileExtension (fileName) {
return (fileName.lastIndexOf('.') >= 0) ? fileName.substr(fileName.lastIndexOf('.')).toLowerCase() : ''
}
Expand All @@ -256,5 +267,6 @@ module.exports = {
removeTrackFolder,
upload,
uploadTempDiskStorage,
trackFileUpload
trackFileUpload,
handleTrackContentUpload
}
2 changes: 1 addition & 1 deletion creator-node/src/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = function (app) {
storagePath: fileResp.storagePath,
type: 'image',
dirMultihash: resizeResp.dir.dirCID,
fileName: fileResp.path.split('/').slice(-1)[0]
fileName: fileResp.sourceFile.split('/').slice(-1)[0]
},
transaction: t }))[0].dataValues

Expand Down
5 changes: 3 additions & 2 deletions creator-node/src/routes/tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { Buffer } = require('ipfs-http-client')

const { getSegmentsDuration } = require('../segmentDuration')
const models = require('../models')
const { saveFileFromBuffer, saveFileToIPFSFromFS, removeTrackFolder, trackFileUpload } = require('../fileManager')
const { saveFileFromBuffer, saveFileToIPFSFromFS, removeTrackFolder, handleTrackContentUpload } = require('../fileManager')
const { handleResponse, successResponse, errorResponseBadRequest, errorResponseServerError, errorResponseForbidden } = require('../apiHelpers')
const { getFileUUIDForImageCID, rehydrateIpfsFromFsIfNecessary } = require('../utils')
const { authMiddleware, ensurePrimaryMiddleware, syncLockMiddleware, triggerSecondarySyncs } = require('../middlewares')
Expand All @@ -16,7 +16,8 @@ module.exports = function (app) {
* @dev - currently stores each segment twice, once under random file UUID & once under IPFS multihash
* - this should be addressed eventually
*/
app.post('/track_content', authMiddleware, ensurePrimaryMiddleware, syncLockMiddleware, trackFileUpload.single('file'), handleResponse(async (req, res) => {
app.post('/track_content', authMiddleware, ensurePrimaryMiddleware, syncLockMiddleware, handleTrackContentUpload, handleResponse(async (req, res) => {
if (req.fileSizeError) return errorResponseBadRequest(req.fileSizeError)
if (req.fileFilterError) return errorResponseBadRequest(req.fileFilterError)
const routeTimeStart = Date.now()
let codeBlockTimeStart = Date.now()
Expand Down

0 comments on commit 1cfc3a6

Please sign in to comment.