Created
May 5, 2011 14:24
-
-
Save jharlap/957127 to your computer and use it in GitHub Desktop.
riak-js interacting with file upload, causing strange stall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
This is chopped down from a multi-kloc app, which explains why Connect is involved | |
and why I would even care to do a riak.get and ignore its result. The issue here is | |
that if RUN_TEST is 1, doing the riak.get frequently causes the file upload to stall, | |
while when RUN_TEST is 0 and riak.get is skipped, the file upload works reliably. | |
### | |
connect = require 'connect' | |
fs = require 'fs' | |
riak = require('riak-js').getClient() | |
routes = (app) -> | |
app.put '/:RUN_TEST/:key', (req, res) -> | |
handleUpload = () -> | |
filename = "/tmp/blahblah_#{new Date().getTime()}" | |
console.log "Writing to #{filename}" | |
fileStream = fs.createWriteStream filename | |
fileStream.on 'error', (err) -> | |
console.log "Error on filestream: #{err}" | |
res.writeHead 500 | |
res.end() | |
req.on 'end', () -> | |
console.log "req ended" | |
fileStream.end() | |
res.writeHead 204 | |
res.end() | |
req.pipe fileStream, end:false | |
req.resume() | |
if req.params.RUN_TEST is '1' then riak.get 'bucket', 'key', (err, data) -> handleUpload() | |
else handleUpload() | |
server = connect.createServer() | |
server.use '/', connect.router routes | |
server.listen 8123, "127.0.0.1" | |
console.log 'Server running at http://127.0.0.1:8123/' | |
console.log "Now run: curl -v -X PUT -H 'Content-Type: image/jpeg' -d @/path/to/img.jpg http://localhost:8123/1/mytestimg1" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution: req.pause() before doing riak.get.