Race condition in Client

5 views
Skip to first unread message

Hagen

unread,
Jun 15, 2009, 8:01:30 AM6/15/09
to nodejs
Next bug:

The way I read the API is that I can use one instance of
node.http.Client and issue several requests. However, these requests
are not synchronized, i.e. if they overlap, I do get:

http.js:390: Socket is not open for writing
connection.send(out[0], out[1]);

But thanks to the asynchronous nature of node.js, it's almost
impossible to do the synchronization myself. Do you consider this a
bug in node.js? If no, reusing a client is almost impossible and I
will have to resort to calling new node.http.Client every time, which
in turn will probably cause a new connection instead of pipelining the
requests on a single connection (which I was expecting).

ry

unread,
Jun 15, 2009, 12:28:51 PM6/15/09
to nodejs
Hi Hagen,

> The way I read the API is that I can use one instance of
> node.http.Client and issue several requests. However, these requests
> are not synchronized, i.e. if they overlap, I do get:

I don't understand. What do you mean by overlap? http.Client ought to
queue the requests and issue them sequentially. At the moment there is
no pipelining, it restarts the connection after each response - but
that will hopefully be added in the future. (I also want to allow for
the possibility of using up to 2 connections per http.Client to issue
multiple requests at a time.)

> http.js:390: Socket is not open for writing
> connection.send(out[0], out[1]);

It's probably a bug. Can you show me how to reproduce?

ry

Hagen Overdick

unread,
Jun 15, 2009, 1:15:20 PM6/15/09
to nod...@googlegroups.com

> http.js:390: Socket is not open for writing
>         connection.send(out[0], out[1]);

It's probably a bug. Can you show me how to reproduce?

var client = new node.http.Client(5984);

function fetch(data) {
return {
execute : function(groupHandler) {
var fetchCounter = 0;
for (var key in data) {
if (data.hasOwnProperty(key)) {
var job = data[key];
var path = job[0];
var callHandler = job[1];
fetchCounter += 1;
client.get(path).finish(function(response) {
puts("Finishing request to " + path);
response.setBodyEncoding("utf8");
var result = "";

response.onBody = function(chunk) {
result += chunk;
};
response.onBodyComplete = function() {
data[key] = callHandler(response, result);
fetchCounter -= 1;
if (fetchCounter === 0) {
puts("Group Handler");
groupHandler(data);
}
};
});
}
};
}
};
}


fetch({
foo : [
"/", 
function(response,result) {
return result;
}
]
}).execute(function(result) {
fetch({
foo : [
"/", 
function(response,result) {
return result;
}
]
}).execute(function(result) {
puts("Success");
});
});

---

brickmirror:proxy sixtus$ node /Users/sixtus/temp/clientbug.js 
http.js:390: Socket is not open for writing
Finishing request to /
        connection.send(out[0], out[1]);
                   ^

---

Creating a new client helps.
 

ry

unread,
Jun 15, 2009, 8:03:31 PM6/15/09
to nodejs
Hi Hagen:

Thanks for pointing this out. It looks like a bug. I'll check it out
tomorrow.

ry

ryan dahl

unread,
Jun 16, 2009, 2:53:27 PM6/16/09
to nod...@googlegroups.com
On Mon, Jun 15, 2009 at 2:01 PM, Hagen<six...@gmail.com> wrote:
>
> Next bug:
>
> The way I read the API is that I can use one instance of
> node.http.Client and issue several requests. However, these requests
> are not synchronized, i.e. if they overlap, I do get:
>
> http.js:390: Socket is not open for writing
>        connection.send(out[0], out[1]);
>

Fixed in d77f75774516fc9dfefe6c6523a94960df5100b5

Reply all
Reply to author
Forward
0 new messages