4

First off, thank you @Moishe for the very useful API. I'm having a little timeout problem, maybe someone knows the answer. Here's how I open the channel:

var openChannel = function () {
    var channel = new goog.appengine.Channel($('#token').val());
    var socket = channel.open();
    socket.onopen = function () {};
    socket.onmessage = function (m) {
        var message = JSON.parse(m.data);
        // do stuff
    };
    socket.onerror = function (error) { alert(error); };
    socket.onclose = openChannel;
};
openChannel();

This works fine, I post my messages and they go to the other clients pretty quickly. But if I stay on the page for roughly 15 minutes, the server loses track of my channel. In dev, it throws an error (which I saw was a known bug: http://www.mail-archive.com/google-appengine@googlegroups.com/msg44609.html). But in prod, it still ignores messages on that channel after about 15 minutes.

We fixed it by adding a setInterval(getSomeUrl, everyMinute) to the page, but we'd rather not have to do that. I noticed in Moishe's last commit for the trivia game sample that he took out a keep-alive. I didn't understand how he replaced it, and what he meant by onopen is reliable:

http://code.google.com/p/trivia-quiz/source/browse/trunk/src/index.html

Update: Server side code is

class Home(BaseHandler):
    def get(self):
        self.checkUser()

        if self.user:
            userId = self.user.user_id()
            token = channel.create_channel(userId)
            chatClients[userId] = token
            self.model['token'] = token
            players = self.checkChatRoom()
            self.model['users'] = players
            self.model['messages'] = map(lambda k:db.get(k), self.chat_room.messages) # TODO: Replace this line and the next with a query
            self.model['messages'] = sorted(self.model['messages'], key=lambda m: m.timestamp, reverse=True)
            self.writeTemplate('index.html')

BaseHandler is just a base class I use for all my GAE handlers, it provides checkUser which redirects if the user isn't logged in, and it provides writeTemplate which takes what's in self.model and writes it in a template. It's just a proof of concept, so no cache or anything else other than what's above.

Milimetric
  • 13,411
  • 4
  • 44
  • 56
  • Interesting... the channel should stay alive for 2 hours; after that you should get an error. I assume, since you didn't mention it, that you aren't getting an error. Are you getting an onclose callback? How frequently are you sending messages & how big are they? This shouldn't change anything (up to quota limits, of course) but if you're an outlier maybe there's a bug. – Moishe Lettvin Jun 13 '11 at 12:54
  • I'm doing that `onerror` popup alert thing and not seeing it ever. I'm also not getting the `onclose` because that would open the channel again. I'm seeing this in dev and prod, so that's surprising that I'm not making an obvious mistake. I'll have both versions of the app (with setInterval and without) up on the web a little later today, I'll add the URLs here. – Milimetric Jun 13 '11 at 13:36
  • Ok, so the app that has the problem is at: http://strategy-games.appspot.com/. Right now that main page has polling, so you can see the no polling example here: http://strategy-games.appspot.com/no-polling. Thanks very much for your help. – Milimetric Jun 13 '11 at 21:16
  • Interesting: I tried this app and it looks like it "loses" the context of a particular user. I left the page open and not only does it stop receiving messages, it also stops being able to _send_ them. Is it possible that something's expiring from a cache or something like that? Inspecting the network traffic, it appears that the channel is still active after about 30 minutes. – Moishe Lettvin Jun 14 '11 at 23:33
  • Yeah, I think it's weird too :). I can give you access to our repository if you'd like. I edited the above with the server side code. – Milimetric Jun 14 '11 at 23:58
  • I have something very similar on my side too - after some time, the client can neither send nor receive any message through the channel. Using GWT and gwt-channel for my part, and looking at the logs nothing seems to occur when the connection is lost. Please note that for me this happens only in production environment, not in dev – Sébastien Tromp Aug 08 '11 at 15:45
  • that makes sense, the new version probably cleared up the dev problem. I haven't heard back about it yet from @Moishe, but looking forward to any news. – Milimetric Aug 08 '11 at 18:47
  • do you have any news on this? It seems the delay after which you "lose" connection is very short (a couple of minutes for me). I will try and play with keep-alives to see if this could solve the issue. – Sébastien Tromp Aug 20 '11 at 11:00
  • Nope, I know no more than you. We could use an answer on this, but so far keep-alives have been working for me. Though, like I said, it kind of defeats the purpose. – Milimetric Aug 20 '11 at 15:17
  • I just noticed the timeout in my own app what is happening with this http://code.google.com/p/googleappengine/issues/detail?id=4940 –  Dec 13 '12 at 16:05
  • 1
    The lead developer on this, @Moishe, never addressed the problem. I have since moved on to other solutions. The meteor framework incorporates a great real-time communication system. Firebase is an interesting choice, and setting up socket.io on Heroku is not that hard (I suggest being on linux for that though). – Milimetric Dec 13 '12 at 17:02

0 Answers0