Discussion:
Sometimes my MUC aren't sent :(
StuFF mc
2010-03-25 15:44:34 UTC
Permalink
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg

Anybody would know why?

Cheers.
Erik Elmore
2010-03-25 17:31:43 UTC
Permalink
You are trying to send a message in the same thread as the handler. I know
that isn't ideal, but I don't know if it might cause a deadlock condition or
raise errors, however.

+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
StuFF mc
2010-03-25 17:35:00 UTC
Permalink
? In the same thread? How would you do else?
You are trying to send a message in the same thread as the handler.  I know
that isn't ideal, but I don't know if it might cause a deadlock condition or
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
StuFF mc
2010-03-25 17:58:23 UTC
Permalink
Also what's the best way to investigate on such an issue :( I checked
from Adium it works perfectly from Jabber's side, so there's
definetely something wrong with either my code or (I doubt) XMPP.

But this code was working until recently. I don't know what I might
have changed (also looking at Git it doesn't strike me).

Once the "send" is sent, isn't there some kind of "confirmation" that
the message arrived?
Post by StuFF mc
? In the same thread? How would you do else?
You are trying to send a message in the same thread as the handler.  I know
that isn't ideal, but I don't know if it might cause a deadlock condition or
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
Erik Elmore
2010-03-25 18:06:44 UTC
Permalink
Keep in mind that if the decode thread raises errors, you might not
necessarily see any output at all. The begin..rescue..end block within the
callback structure I just posted is the best way I've found to detect errors
within the decode thread.

+=
Erik Elmore
Post by StuFF mc
Also what's the best way to investigate on such an issue :( I checked
from Adium it works perfectly from Jabber's side, so there's
definetely something wrong with either my code or (I doubt) XMPP.
But this code was working until recently. I don't know what I might
have changed (also looking at Git it doesn't strike me).
Once the "send" is sent, isn't there some kind of "confirmation" that
the message arrived?
Post by StuFF mc
? In the same thread? How would you do else?
Post by Erik Elmore
You are trying to send a message in the same thread as the handler. I
know
Post by StuFF mc
Post by Erik Elmore
that isn't ideal, but I don't know if it might cause a deadlock
condition or
Post by StuFF mc
Post by Erik Elmore
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
StuFF mc
2010-03-25 18:11:00 UTC
Permalink
I think my problem is more about Private messages... Your code would
work in my code, since I already checked that. Sending a message in
the Chat Room works.

What doesn't (and did until recently) is sending a private message to
someone in the room (actually to the one appearing in the room, and in
your case to the one sending the command). Would you mind checking if
your code works if you send back the "some message" only to the user
who has initiated the command?
Post by Erik Elmore
Keep in mind that if the decode thread raises errors, you might not
necessarily see any output at all.  The begin..rescue..end block within the
callback structure I just posted is the best way I've found to detect errors
within the decode thread.
+=
Erik Elmore
Post by StuFF mc
Also what's the best way to investigate on such an issue :( I checked
from Adium it works perfectly from Jabber's side, so there's
definetely something wrong with either my code or (I doubt) XMPP.
But this code was working until recently. I don't know what I might
have changed (also looking at Git it doesn't strike me).
Once the "send" is sent, isn't there some kind of "confirmation" that
the message arrived?
Post by StuFF mc
? In the same thread? How would you do else?
You are trying to send a message in the same thread as the handler.  I know
that isn't ideal, but I don't know if it might cause a deadlock condition or
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
StuFF mc
2010-03-25 18:12:29 UTC
Permalink
And I should mention that I use m.from.resource ( "m" being the
presence object from the @muc.add_join_callback). I also tried with
the complete "room-WQCBuIXaXYjQT0dZR+***@public.gmane.org/resource" and in this case as we all
know the resource is the user, but it doesn't work either...
Post by StuFF mc
I think my problem is more about Private messages... Your code would
work in my code, since I already checked that. Sending a message in
the Chat Room works.
What doesn't (and did until recently) is sending a private message to
someone in the room (actually to the one appearing in the room, and in
your case to the one sending the command). Would you mind checking if
your code works if you send back the "some message" only to the user
who has initiated the command?
Post by Erik Elmore
Keep in mind that if the decode thread raises errors, you might not
necessarily see any output at all.  The begin..rescue..end block within the
callback structure I just posted is the best way I've found to detect errors
within the decode thread.
+=
Erik Elmore
Post by StuFF mc
Also what's the best way to investigate on such an issue :( I checked
from Adium it works perfectly from Jabber's side, so there's
definetely something wrong with either my code or (I doubt) XMPP.
But this code was working until recently. I don't know what I might
have changed (also looking at Git it doesn't strike me).
Once the "send" is sent, isn't there some kind of "confirmation" that
the message arrived?
Post by StuFF mc
? In the same thread? How would you do else?
You are trying to send a message in the same thread as the handler.  I know
that isn't ideal, but I don't know if it might cause a deadlock condition or
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
Erik Elmore
2010-03-25 18:19:22 UTC
Permalink
I have a method that sends private messages and I can confirm that it works
in response to commands. I don't have it sending messages in response to
join events, but it does process join events for the purposes of tracking
the state of room occupants. This method could be called from the last
method I posted right after the line with "begin".

def notify_nick( nick, body, html = nil )
reply = Jabber::Message.new
reply.body = body
unless html.nil?
reply.body = 'If you can see this, you need to use a client that
supports XHTML messages.' if body.nil?
reply.add_element(Jabber::XHTML::HTML.new(html))
end
@muc.send(reply, nick)
end

+=
Erik Elmore
Post by StuFF mc
And I should mention that I use m.from.resource ( "m" being the
know the resource is the user, but it doesn't work either...
Post by StuFF mc
I think my problem is more about Private messages... Your code would
work in my code, since I already checked that. Sending a message in
the Chat Room works.
What doesn't (and did until recently) is sending a private message to
someone in the room (actually to the one appearing in the room, and in
your case to the one sending the command). Would you mind checking if
your code works if you send back the "some message" only to the user
who has initiated the command?
Post by Erik Elmore
Keep in mind that if the decode thread raises errors, you might not
necessarily see any output at all. The begin..rescue..end block within
the
Post by StuFF mc
Post by Erik Elmore
callback structure I just posted is the best way I've found to detect
errors
Post by StuFF mc
Post by Erik Elmore
within the decode thread.
+=
Erik Elmore
Post by StuFF mc
Also what's the best way to investigate on such an issue :( I checked
from Adium it works perfectly from Jabber's side, so there's
definetely something wrong with either my code or (I doubt) XMPP.
But this code was working until recently. I don't know what I might
have changed (also looking at Git it doesn't strike me).
Once the "send" is sent, isn't there some kind of "confirmation" that
the message arrived?
Post by StuFF mc
? In the same thread? How would you do else?
Post by Erik Elmore
You are trying to send a message in the same thread as the handler.
I
Post by StuFF mc
Post by Erik Elmore
Post by StuFF mc
Post by StuFF mc
Post by Erik Elmore
know
that isn't ideal, but I don't know if it might cause a deadlock condition or
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
StuFF mc
2010-03-25 18:23:50 UTC
Permalink
just to be sure... what's "nick" - is it just "user123", without any @
or / ? :-) Just to be sure, once again, coz if it's the case, that's
exactly my code, and nope, it doesn't work in my case :(

The only difference would be the way the message is build, but since I
can see the "body" in the XML and it works speaking to the room, I'd
be clueless... (but hey! thanks for your help in *any* case)
Post by Erik Elmore
I have a method that sends private messages and I can confirm that it works
in response to commands.  I don't have it sending messages in response to
join events, but it does process join events for the purposes of tracking
the state of room occupants.  This method could be called from the last
method I posted right after the line with "begin".
  def notify_nick( nick, body, html = nil )
    reply = Jabber::Message.new
    reply.body = body
    unless html.nil?
      reply.body = 'If you can see this, you need to use a client that
supports XHTML messages.' if body.nil?
      reply.add_element(Jabber::XHTML::HTML.new(html))
    end
  end
+=
Erik Elmore
Post by StuFF mc
And I should mention that I use m.from.resource ( "m" being the
know the resource is the user, but it doesn't work either...
Post by StuFF mc
I think my problem is more about Private messages... Your code would
work in my code, since I already checked that. Sending a message in
the Chat Room works.
What doesn't (and did until recently) is sending a private message to
someone in the room (actually to the one appearing in the room, and in
your case to the one sending the command). Would you mind checking if
your code works if you send back the "some message" only to the user
who has initiated the command?
Post by Erik Elmore
Keep in mind that if the decode thread raises errors, you might not
necessarily see any output at all.  The begin..rescue..end block within the
callback structure I just posted is the best way I've found to detect errors
within the decode thread.
+=
Erik Elmore
Post by StuFF mc
Also what's the best way to investigate on such an issue :( I checked
from Adium it works perfectly from Jabber's side, so there's
definetely something wrong with either my code or (I doubt) XMPP.
But this code was working until recently. I don't know what I might
have changed (also looking at Git it doesn't strike me).
Once the "send" is sent, isn't there some kind of "confirmation" that
the message arrived?
Post by StuFF mc
? In the same thread? How would you do else?
Post by Erik Elmore
You are trying to send a message in the same thread as the
handler.  I
know
that isn't ideal, but I don't know if it might cause a deadlock
condition or
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
Erik Elmore
2010-03-25 18:33:12 UTC
Permalink
nick is just that, the resource of the occupant's jid. For example, your
room is "room" on domain "muc.domain.com" and you join the room with the
nick of "nick", then the full jid of this occupant would be
room-wTFq1i7f5pQ4Q++***@public.gmane.org/nick. In this scenario the variable nick would be
plainly "nick" by the time this method were called. I see one difference
between mine and your code. When you construct a Jabber::Message, you set
the recipient's address. Try constructing the Jabber::Message object with a
nil recipient and then just use the second parameter to @muc.send for that.
The MUCClient class does a little magic when processing a message stanza
object--it fixes the message type and the recipient address, but it might
only do that if the recipient is nil.

+=
Erik Elmore
Post by StuFF mc
or / ? :-) Just to be sure, once again, coz if it's the case, that's
exactly my code, and nope, it doesn't work in my case :(
The only difference would be the way the message is build, but since I
can see the "body" in the XML and it works speaking to the room, I'd
be clueless... (but hey! thanks for your help in *any* case)
Post by Erik Elmore
I have a method that sends private messages and I can confirm that it
works
Post by Erik Elmore
in response to commands. I don't have it sending messages in response to
join events, but it does process join events for the purposes of tracking
the state of room occupants. This method could be called from the last
method I posted right after the line with "begin".
def notify_nick( nick, body, html = nil )
reply = Jabber::Message.new
reply.body = body
unless html.nil?
reply.body = 'If you can see this, you need to use a client that
supports XHTML messages.' if body.nil?
reply.add_element(Jabber::XHTML::HTML.new(html))
end
@muc.send(reply, nick)
end
+=
Erik Elmore
Post by StuFF mc
And I should mention that I use m.from.resource ( "m" being the
know the resource is the user, but it doesn't work either...
Post by StuFF mc
I think my problem is more about Private messages... Your code would
work in my code, since I already checked that. Sending a message in
the Chat Room works.
What doesn't (and did until recently) is sending a private message to
someone in the room (actually to the one appearing in the room, and in
your case to the one sending the command). Would you mind checking if
your code works if you send back the "some message" only to the user
who has initiated the command?
Post by Erik Elmore
Keep in mind that if the decode thread raises errors, you might not
necessarily see any output at all. The begin..rescue..end block
within
Post by Erik Elmore
Post by StuFF mc
Post by StuFF mc
Post by Erik Elmore
the
callback structure I just posted is the best way I've found to detect errors
within the decode thread.
+=
Erik Elmore
Post by StuFF mc
Also what's the best way to investigate on such an issue :( I
checked
Post by Erik Elmore
Post by StuFF mc
Post by StuFF mc
Post by Erik Elmore
Post by StuFF mc
from Adium it works perfectly from Jabber's side, so there's
definetely something wrong with either my code or (I doubt) XMPP.
But this code was working until recently. I don't know what I might
have changed (also looking at Git it doesn't strike me).
Once the "send" is sent, isn't there some kind of "confirmation"
that
Post by Erik Elmore
Post by StuFF mc
Post by StuFF mc
Post by Erik Elmore
Post by StuFF mc
the message arrived?
Post by StuFF mc
? In the same thread? How would you do else?
Post by Erik Elmore
You are trying to send a message in the same thread as the handler. I
know
that isn't ideal, but I don't know if it might cause a deadlock
condition or
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
StuFF mc
2010-03-26 08:51:32 UTC
Permalink
Forgot to get back to you on this yesterday... Turns out I also saw
this only difference, and I tried with nil... But nope, doesn't make
any difference :(

Once again the weirdest thing is that this code worked until very recently.
nick is just that, the resource of the occupant's jid.  For example, your
room is "room" on domain "muc.domain.com" and you join the room with the
nick of "nick", then the full jid of this occupant would be
plainly "nick" by the time this method were called.  I see one difference
between mine and your code.  When you construct a Jabber::Message, you set
the recipient's address.  Try constructing the Jabber::Message object with a
The MUCClient class does a little magic when processing a message stanza
object--it fixes the message type and the recipient address, but it might
only do that if the recipient is nil.
+=
Erik Elmore
Post by StuFF mc
or / ? :-) Just to be sure, once again, coz if it's the case, that's
exactly my code, and nope, it doesn't work in my case :(
The only difference would be the way the message is build, but since I
can see the "body" in the XML and it works speaking to the room, I'd
be clueless... (but hey! thanks for your help in *any* case)
Post by Erik Elmore
I have a method that sends private messages and I can confirm that it works
in response to commands.  I don't have it sending messages in response to
join events, but it does process join events for the purposes of tracking
the state of room occupants.  This method could be called from the last
method I posted right after the line with "begin".
  def notify_nick( nick, body, html = nil )
    reply = Jabber::Message.new
    reply.body = body
    unless html.nil?
      reply.body = 'If you can see this, you need to use a client that
supports XHTML messages.' if body.nil?
      reply.add_element(Jabber::XHTML::HTML.new(html))
    end
  end
+=
Erik Elmore
Post by StuFF mc
And I should mention that I use m.from.resource ( "m" being the
know the resource is the user, but it doesn't work either...
Post by StuFF mc
I think my problem is more about Private messages... Your code would
work in my code, since I already checked that. Sending a message in
the Chat Room works.
What doesn't (and did until recently) is sending a private message to
someone in the room (actually to the one appearing in the room, and in
your case to the one sending the command). Would you mind checking if
your code works if you send back the "some message" only to the user
who has initiated the command?
Post by Erik Elmore
Keep in mind that if the decode thread raises errors, you might not
necessarily see any output at all.  The begin..rescue..end block
within
the
callback structure I just posted is the best way I've found to detect
errors
within the decode thread.
+=
Erik Elmore
Post by StuFF mc
Also what's the best way to investigate on such an issue :( I checked
from Adium it works perfectly from Jabber's side, so there's
definetely something wrong with either my code or (I doubt) XMPP.
But this code was working until recently. I don't know what I might
have changed (also looking at Git it doesn't strike me).
Once the "send" is sent, isn't there some kind of "confirmation" that
the message arrived?
Post by StuFF mc
? In the same thread? How would you do else?
On Thu, Mar 25, 2010 at 6:31 PM, Erik Elmore
Post by Erik Elmore
You are trying to send a message in the same thread as the
handler.  I
know
that isn't ideal, but I don't know if it might cause a deadlock
condition or
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
Erik Elmore
2010-03-25 18:03:39 UTC
Permalink
XMPP4R uses a thread that is separate from the main thread to do its I/O
over the XML stream. Whenever that thread receives a message that has
callbacks associated, those callback routines are executed in the context of
that separate thread. It might be the case that if you create new XML
stream I/O activity from within that same thread, then it could lead to a
deadlock or some other side effect under certain conditions--which might
explain the intermittent nature of your problem. I think this happens
because if you block execution inside a callback, then all stream I/O is
also blocked (although I don't have the code in front of me now, so I'm
going from memory here).

When my code receives a message to which respond with another message, I
spawn a new thread to get that work done. The following code snippet is
(mostly) taken directly from a bot framework I've been working on. This
method is for message handling (as opposed to presence handling like yours),
so it checks to make sure the message contains a recognized command string
and that the message is not a delayed delivery (which might not matter in a
join callback). Look at how lines 6 to 13 establish a new thread to send
the reply and also set up the proper error handling so it doesn't just crash
without telling you. I should add that having it log errors instead of
sending them as XMPP messages would be better, but I was lazy that day.

@client is the Jabber::Client object and @muc is a related
Jabber::MUC::MUCClient object.

http://pastie.textmate.org/886921

def base_message_handler( msg )
msg_handled = false
if !msg.body.nil? && (m = @cmd_rx.match(msg.body.strip)) &&
@commands.keys.include?(m[1])
msg_handled = true
Thread.new do
begin
@muc.send Jabber::Message.new(nil, "some message")
rescue Exception => e
reply = "Error while responding to command:\n%s\n%s" % [e.message,
e.backtrace.join("\n")]
@client.send(Jabber::Message.new(msg.from, reply))
end
end unless msg.delayed?
end
msg_handled
end


+=
Erik Elmore
Post by StuFF mc
? In the same thread? How would you do else?
Post by Erik Elmore
You are trying to send a message in the same thread as the handler. I
know
Post by Erik Elmore
that isn't ideal, but I don't know if it might cause a deadlock condition
or
Post by Erik Elmore
raise errors, however.
+=
Erik Elmore
Post by StuFF mc
http://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
Nick Thomas
2010-03-26 08:52:48 UTC
Permalink
Post by Erik Elmore
You are trying to send a message in the same thread as the handler. I
know that isn't ideal, but I don't know if it might cause a deadlock
condition or raise errors, however.
+=
Erik Elmore
Having just used XMPP4r to build the xmpp notifier of an alerting tool
(think nagios, but not - to be open-sourced in the nearish future), I'm
wondering if I've inadvertently fallen foul of this - although I'm not
seeing any symptoms yet!

My code (more or less) - the idea being to automatically accept
subscriptions and add the subscribee to the roster:

class XmppNotifier

attr_accessor :client #Jabber::Client instance
attr_accessor :roster #Jabber::Helper::Roster instance

def connect
# [...]
roster.add_subscription_request_callback do |ri, stanza|
roster.accept_subscription(stanza.from)
jid = JID.new(jid)
ri = roster.find(jid)[jid]
if ri.nil?
roster.add(jid, nil, true)
else
ri.subscribe unless [:to, :both, :remove].include?(ri.subscription)
end
end
# [...]
end

end

So I should be wrapping the contents of the callback in a new thread?

Thanks,

/Nick
StuFF mc
2010-03-26 08:55:46 UTC
Permalink
Well in my case it doesn't make any difference, with or without
another thread....
Post by Nick Thomas
You are trying to send a message in the same thread as the handler.  I
know that isn't ideal, but I don't know if it might cause a deadlock
condition or raise errors, however.
+=
Erik Elmore
Having just used XMPP4r to build the xmpp notifier of an alerting tool
(think nagios, but not - to be open-sourced in the nearish future), I'm
wondering if I've inadvertently fallen foul of this - although I'm not
seeing any symptoms yet!
My code (more or less) - the idea being to automatically accept
class XmppNotifier
 attr_accessor :client #Jabber::Client instance
 attr_accessor :roster #Jabber::Helper::Roster instance
 def connect
   # [...]
   roster.add_subscription_request_callback do |ri, stanza|
     roster.accept_subscription(stanza.from)
     jid = JID.new(jid)
     ri = roster.find(jid)[jid]
     if ri.nil?
       roster.add(jid, nil, true)
     else
       ri.subscribe unless [:to, :both, :remove].include?(ri.subscription)
     end
   end
   # [...]
 end
end
So I should be wrapping the contents of the callback in a new thread?
Thanks,
/Nick
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
Nick Thomas
2010-03-26 09:03:32 UTC
Permalink
Post by StuFF mc
Well in my case it doesn't make any difference, with or without
another thread....
Do not invoke this in a callback but in a seperate thread because
we may not suspend the parser-thread (in whose context callbacks
are executed).
And it seems both the methods I'm using hit on that (and in fact,
roster.add blocks waiting for a response).

I think I might add a thread just to be on the safe side - I get the
horrible feeling that I'm not encountering problems just because I'm
doing low-traffic stuff at the moment...

/Nick
StuFF mc
2010-03-26 09:12:43 UTC
Permalink
If it's only about wrapper the code around a "Thread.new do end"
block, I will as well do it, to be sure.

BY THE WAY: guys.... Sorry for all this (well actually it got us
speaking about Threads which is good!) but it turns out the problem
wasn't my code, but Adium! Totally weird. I use Adium (and/or PSI +
iChat) all the time to check/test and for whatever reason the message
wasn't "popping" in Adium. I saw it was working in the iPhone app
receiving the message and I just restarted Adium to check and boom! it
works...

So the conclusion to this is:

1. Use Thread Blocks, it doesn't hurt at all I guess (except maybe the
readability of your code)
2. Don't trust Adium, or any other - or actually always have them 3
open and if something doesn't work in one check in the other.

Thank you all. Cheers.
Post by Nick Thomas
Post by StuFF mc
Well in my case it doesn't make any difference, with or without
another thread....
Do not invoke this in a callback but in a seperate thread because
we may not suspend the parser-thread (in whose context callbacks
are executed).
And it seems both the methods I'm using hit on that (and in fact,
roster.add blocks waiting for a response).
I think I might add a thread just to be on the safe side - I get the
horrible feeling that I'm not encountering problems just because I'm
doing low-traffic stuff at the moment...
/Nick
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
Nick Thomas
2010-03-26 09:24:04 UTC
Permalink
Post by StuFF mc
1. Use Thread Blocks, it doesn't hurt at all I guess (except maybe the
readability of your code)
2. Don't trust Adium, or any other - or actually always have them 3
open and if something doesn't work in one check in the other.
Thank you all. Cheers.
Yum, threads :). Glad you got it all sorted in the end.

Hijacking this thread slightly - I want to start adding tests for my
XMPP code, and have come across Jabber::Test::ListenerMocker - which
seems to be undocumented. Has anyone used it / has docs / suggestions
for testing xmpp4r code in general? (I'll be integrating it with
Test::Unit and rspec, I guess).

Just about to go look through the xmpp4r tests themselves, to see if I
can glean any hints...

/Nick
Nick Thomas
2010-03-26 09:53:13 UTC
Permalink
Post by Nick Thomas
Having just used XMPP4r to build the xmpp notifier of an alerting tool
(think nagios, but not - to be open-sourced in the nearish future),
Hmm, it turns out we've already released it - see:
https://projects.bytemark.co.uk/projects/mauvealert/repository

I'm not plugging, just thought the XMPP4r developers might like to see
their library being put to good use :)

/Nick

Loading...