alaingilbert / Turntable-API

Allows you to create bots for turntable.fm
http://alaingilbert.github.com/Turntable-API/
MIT License
318 stars 97 forks source link

Logging stops after a few messages #196

Closed MikeWills closed 11 years ago

MikeWills commented 11 years ago

I am trying to track down where this is happening. I can start a bot (on any computer) and it will long for a few minutes then just stop. I believe I am running node .10.5. Has anyone else come across this? I doesn't matter if I am running interactive or not.

Izzmo commented 11 years ago

I assume you mean log? If you go into the REPL session, is the socket still connected?

MikeWills commented 11 years ago

I am just doing console.log. I am not using REPL. Here is the the bot I am working on.

Izzmo commented 11 years ago

Well node always has a REPL session open, you can choose to open another. I assume you are using a service to run the bot, not locally? If so, then you most likely wouldn't have access to the main REPL session anyways to play around with it and see what it's doing.

In that case, can you do some more logging and see if the socket is still connected? I will have a large number of my ttstats bots, every now and then, all terminate at the same time. It usually happens when a chat server is reset and all the bots on that chat server must the reconnect. Sometimes when this happens, your bot stays connected, or a timeout or end session is never received and your socket just kind of sits there with nothing happening. I have checks in place against this to see when a message was last since and at a variable time, it will attempt to reconnect the socket.

Maybe that is what is happening to you?

MikeWills commented 11 years ago

I am running an EC2 instance currently running Ubuntu 12.04. Where would I add these logs? I haven't delved into the core TTAPI yet. But I also have the problem on my personal Ubuntu 12.04 server and on my Mac. So it doesn't seem to be a machine problem.

technobly commented 11 years ago

@MikeWills try something super simple like one of the sample Logging Bots https://github.com/alaingilbert/Turntable-API#logger

And see if it's maybe something you added to your bot recently on even non-recently that's causing an issue.

If you can't run the simple logger bot, then something might be wrong with the fundamentals (Nodejs, TTAPI, Router, Internet)

Divide and conquer.

Speaking of diving into TTAPI... really? you haven't yet... damn get in there and poke around asap!! I was poking all up in there and the websocket code last night. Finally got my bot automatically reconnecting to TT after an internet outage.

Izzmo commented 11 years ago

@MikeWills I guess this might have went without saying, but you are in a room with something going on, right? You won't get messages if no one is talking, no one is playing a song/dj'ing, or joining/leaving the room.

technobly commented 11 years ago

uh yeah, that probably goes without saying... @MikeWills screen is blank? make sure to plug your computer in... :trollface:

MikeWills commented 11 years ago

@DubbyTT Re: reconnecting - Really? I'd like to see how you do that?

The bot hasn't really changed in over a month. So I am really thinking it's something more in the core. Maybe now is the time to log this stuff to mySql instead of the console log.

MikeWills commented 11 years ago

@Izzmo Yes... I am not that stupid. I am in All Music Mix... always someone in here. The bot works fine. Just the logging.

Izzmo commented 11 years ago

Hehe, well I thought I would ask lol, cause I don't really know what else to say without really looking into the code.

gizmotronic commented 11 years ago

I've tested pretty heavily on node.js 0.10.5 and 0.10.6 without any issues, so that doesn't seem likely to be related. The only change I needed to make was related to the crypto module (web console passwords).

The symptom seems to indicate, to me, that you have 2 bots trying to use the same account. Do you have a second instance running anywhere else? Does the same issue happen if you use the account with the web UI?

technobly commented 11 years ago

To know whether or not you are being logged in again from a different location... use this logic:

1) Is your bot leaving the room 3 - 5 seconds after it stops logging chat data? If so it's likely logged into another room. If you log into the Web UI into the lobby while your bot is in the room, this will not disconnect the bot. Only when you register into a room will the connection be severed. You can fan your bot, and then look in your PM list to see if it's still on and what room it's in if it in fact is leaving.

2) If you don't see it in another room, and it's leaving after 3 - 5 seconds, something might be logging in and out momentarily. If you suspect this, you can add a command line interface to your bot and make a command to force it to bot.roomRegister(YOUR_ROOM_ID); . If it joins back in, you have likely been momentarily disconnected by another login process.

3) If either 1 or 2 is not happening, you are likely encountering an infinite loop somewhere in your code. Set up a setInterval( function() { console.log("ping"); }, 5000 ); that will let you know if your bot is still running, or if it's stuck in a loop somewhere.

You can simulate the response of an infinite loop with the following test file:

save as "test.js"

setInterval( function() { console.log("ping"); }, 5000 ); // ping heartbeat every 5 seconds
setTimeout( function() { while(true) {} }, 20000 ); // infinite loop in 20 seconds

run with the command prompt in the directory as "node test.js"

Good luck! :)

MikeWills commented 11 years ago

I forgot to update this. It seems to be running fine again. I did upgrade node in between, but I think it started logging before that. Wish I knew what I did.

technobly commented 11 years ago

Damnit Jim! The fate of the world hinges on this issue. -- we're doomed. ```._ dies...```