Agent doesn't reply to web requests

After a few months of abstinence from the imp I tried my luck on an agent based app today. I must be doing something wrong, because my agent doesn’t do what I expect it to do. Here is my agent code simplified all the way until almost nothing is left:

`http.onrequest( function (request, res)
try {
server.log("Request received: " + request.body);
res.send(200, “okay”);
catch (ex) {
res.send(200, "Oh shit, an error happened while reading input: " + ex);

server.log("Agent done starting, URL is: " + http.agenturl());`

It does start and in the server logs I am told

Agent done starting, URL is:

But when I
curl -d "sheep"

I get

curl: (52) Empty reply from server

Any clues what I am doing wrong?

Hmm, try it again now?

+1 for curling sheep :wink:

It’s working now. Was this some glitch, or is this systematic? Do I need to wait a certain amount of time of agents to go live? I also had trouble blinking up my imp at the same time, could that be related?

There was a glitch with newly created agents yesterday (it affected a small percentage of running agents), which was fixed - one of the reasons agents are still in beta :slight_smile:

I apologize for raising an old thread but I’m having this same issue on a new agent: 231596b4cc1702ee

Occasionally requests get through but mostly timeout out after 2 minutes with “Empty reply from server”. Other agents I’ve tested with are working properly.

We’re looking into this affecting a few developers, should be fixed shortly.


Is there any update on this fix?
If it helps debug, my device is over a year old but I haven’t had http.onrequest() set until recently.

@feesta Could you email me at ?

From what I can see, your agent is burning a lot of CPU time (appears to be in an infinite loop). If this is the case, then it won’t be able to accept HTTP requests as it has to idle to fire event handlers.

Ah, I see! Thanks!
I found the while loop code from the forum not realizing the side-effect. Is there a preferred agent-based equivalent to setInterval?

Yes - use imp.wakeup() like you do on the imp.

eg, run this every 10 seconds:

`function every10() {
// code goes here
imp.wakeup(10, every10);

// start loop