Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

static module hangs when requesting a resource twice #756

Closed
coolaj86 opened this Issue · 6 comments

2 participants

@coolaj86

Tested with Chrome's audio tag, Connect 2.7.3, and node v0.9.10

First I'll get a file to serve:

mkdir -p test-case/{public,priv}
pushd test-case
curl 'http://freedownloads.last.fm/download/487546800/Wheels.mp3' > priv/test.mp3
echo '<html><head><script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script></head><body>Open console to run test</body></html>' > public/index.html

And here's the server.js

(function () {
  "use strict";

  var connect = require('connect')
    , path = require('path')
    , app
    , server
    , port = process.argv[2] || 3000
    ;

  app = connect();
  app.use(connect.static(path.join(__dirname, 'public')));
  app.use('/api/files', connect.static(path.join(__dirname, 'priv')));

  server = app.listen(port, function () {
    console.log('Server running on', server.address());
  });
}());

Run the server

mkdir -p node_modules
npm install connect
node server 3000

Open chrome to http://localhost:3000
Open the console
Run

$('<audio src="http://localhost:3000/api/files/test.mp3">').appendTo('body');

Notice in the network tab that the first request stays pending forever.

Also, try restarting the server and then adding 3 of the same audio element (6 requests):

$('<audio src="http://localhost:3000/api/files/test.mp3" controls="controls">').appendTo('body');
$('<audio src="http://localhost:3000/api/files/test.mp3" controls="controls">').appendTo('body');
$('<audio src="http://localhost:3000/api/files/test.mp3" controls="controls">').appendTo('body');
@tj
Owner
tj commented

sounds more like it may be a range request issue

@tj
Owner
tj commented

can you paste the request header fields?

@coolaj86

From my non-reduced use case:

GET http://localhost:8080/api/files/9eb/9eb13fb08e7e55d9af544da6ef6b9e62.mp3 HTTP/1.1
Referer: http://localhost:8080/
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.99 Safari/537.22
Range: bytes=0-

The other requests shows no headers, it just says pending. Installing wireshark...

I'm verifying whether or not it works with plain-old nginx right now and (so far it's looking like a Chrome audio api bug... more to come)

@tj
Owner
tj commented

hmm perhaps we're not handling 0- correctly, should be fine though

@coolaj86

I'm not able to confirm whether or not the two tests behave the same. There are caching issues at work and also the behavior is different based on whether or not the audio element has been played and then paused or only played or only left paused.

Last time I worked on this project was about 6 months ago and I had to implement a bunch of hacks to get audio api buffers to work properly. It looks like I need to get rid of my old hacks and implement new ones... ugh... the cake is a lie.

Connect

Request

GET /api/files/200/200f3413343d232ba2fe14afff0f0825.mp3 HTTP/1.1
Host: localhost:1232
Connection: keep-alive
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.99 Safari/537.22
Accept: */*
Referer: http://localhost:1232/error
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Range: bytes=0-

Response

HTTP/1.1 206 Partial Content
Vary: Accept-Encoding
Accept-Ranges: bytes
ETag: "3612370-1361981900000"
Date: Wed, 27 Feb 2013 21:53:29 GMT
Cache-Control: public, max-age=0
Last-Modified: Wed, 27 Feb 2013 16:18:20 GMT
Content-Type: audio/mpeg
Content-Range: bytes 0-3612369/3612370
Content-Length: 3612370
Connection: keep-alive

Nginx

Request

GET /api/files/9eb/9eb13fb08e7e55d9af544da6ef6b9e62.mp3 HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.99 Safari/537.22
Accept: */*
Referer: http://localhost:8080/error
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Range: bytes=0-

Response

HTTP/1.1 206 Partial Content
Server: nginx/1.2.6
Date: Wed, 27 Feb 2013 21:42:33 GMT
Content-Type: audio/mpeg
Content-Length: 3977898
Last-Modified: Wed, 27 Feb 2013 16:17:08 GMT
Connection: keep-alive
Content-Range: bytes 0-3977897/3977898
@coolaj86

I think it's safe to close this. It looks like the "pending" request is just a UI placeholder to indicate that several 206 partial requests may handle the single file - there's no actual traffic for it and it never changes, even after the final 206.

Also, only 3 or 4 audio elements may exist on the page at once (and still function as desired). The first must be played and paused before the 2nd or 3rd can be played, and it also depends on whether or not more than one audio element represents the same stream.

Nasty stuff.

(originally I was using 2 audio tags for one stream because the playing stream sometimes wouldn't buffer while playing and so I would play the other faster at 0 volume so that it would need to buffer before the main one and then fill the next chunk of the buffer for both)

Update: it's not just audio tags per page - it's audio tags across all pages.

@coolaj86 coolaj86 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.