Skip to content

Commit

Permalink
Disable keep-alive connections.
Browse files Browse the repository at this point in the history
If there are a sufficient # of connections opened/file descriptors exceeded, Camo will start returning back 404
because of the saturated number of connections.
  • Loading branch information
Roger Hu committed Dec 12, 2014
1 parent 04b1e29 commit a7428d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Camo is configured through environment variables.
* `CAMO_SOCKET_TIMEOUT`: The maximum number of seconds Camo will wait before giving up on fetching an image. (default: 10)
* `CAMO_TIMING_ALLOW_ORIGIN`: The string for Camo to include in the [`Timing-Allow-Origin` header](http://www.w3.org/TR/resource-timing/#cross-origin-resources) it sends in responses to clients. The header is omitted if this environment variable is not set. (default: not set)
* `CAMO_HOSTNAME`: The `Camo-Host` header value that Camo will send. (default: `unknown`)
* `CAMO_KEEP_ALIVE`: Whether or not to enable keep-alive session. (default: `false`)

## Testing Functionality

Expand Down
5 changes: 5 additions & 0 deletions server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ max_redirects = process.env.CAMO_MAX_REDIRECTS || 4
camo_hostname = process.env.CAMO_HOSTNAME || "unknown"
socket_timeout = process.env.CAMO_SOCKET_TIMEOUT || 10
logging_enabled = process.env.CAMO_LOGGING_ENABLED || "disabled"
keep_alive = process.env.CAMO_KEEP_ALIVE || "false"

content_length_limit = parseInt(process.env.CAMO_LENGTH_LIMIT || 5242880, 10)

accepted_image_mime_types = JSON.parse(Fs.readFileSync(
Expand Down Expand Up @@ -83,6 +85,9 @@ process_url = (url, transferredHeaders, resp, remaining_redirects) ->
path: queryPath
headers: transferredHeaders

if keep_alive == "false"
requestOptions['agent'] = false

srcReq = Protocol.get requestOptions, (srcResp) ->
is_finished = true

Expand Down
9 changes: 7 additions & 2 deletions server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7428d5

Please sign in to comment.