0

i'm running javamail on android device. i'm using the jar files suggested in this question's answer:

Sending Email in Android using JavaMail API without using the default/built-in app

when i'm causing a connection lost from the android device (turning on\off wifi, setting airplane mode) every function called, that accessing the javamail socket, is not returning. example of stuck function (i'v tried to call functions on the FOLDER objects and on STORE objects:

close()

forceClose()

getType()

no exception is being thrown (tried to throw exception in the scope - it get caught) no error log is shown on the logcat

it is important to mention the "removeMessageCounterLister" function works fine and the thread not getting stuck after the call

i have jdk7 if it matters.

thank you so much for your answer


update: this problem doesn't have any relation the timeout connections. i'v set the timeout and connection timeout params and they only affect the idle() function.

when the thread get stuck the message that the javamail log is writing is "DONE"

Community
  • 1
  • 1

1 Answers1

1

You probably need to configure some timeouts, both connection timeouts and I/O timeouts. See the javadocs for the protocol packages for the list of properties you can set, for example the com.sun.mail.imap package

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40
  • i'v tried to do it. i have configured all the timeouts i found. – Eran Shorer Oct 18 '12 at 08:55
  • i'v also tried to put connection timeout using mail.imaps.connectiontimeout and mail.imaps.timeout. it causes the idle to stop after the timeout, but not solving the close() and forceClose() being stuck – Eran Shorer Oct 18 '12 at 09:32
  • when the thread get stuck the message that the javamail log is writing is "DONE" – Eran Shorer Oct 18 '12 at 10:08
  • I see that you're setting the mail.imaps.timeout property. Just to be sure, are you getting the Store using session.getStore("imaps")? If so, it should work, but ultimately the timeout configuration is passed to the underlying operating system and thus the actual timeout behavior depends on how the operating system handles timeouts. Note that the "DONE" is sent to terminate the IDLE command. If the connection is already dead when DONE is written, the client should get an IOException. Again, it depends on the JDK and the OS. – Bill Shannon Oct 18 '12 at 20:47
  • It may be an Android bug. Can you reproduce it using real Java? Can you get a stack dump of all the threads when it hangs? – Bill Shannon Oct 30 '12 at 19:12
  • i can't repreduce it because it only happnes on network disconnection from the phone side (airplane mode true and stuff like that) – Eran Shorer Nov 08 '12 at 13:41
  • Run it on a laptop and turn off wifi. – Bill Shannon Nov 08 '12 at 18:14
  • Bill, this looks like a variation of what we are seeing. (Sorry OP for the hijack). This is what we see: 1) Consider a thread calls Store.idle() and the socket read is good. 2) Now if the far-end imap server goes for a graceful shutdown, the idle call catches a MessagingException and the thread terminates. But if something happens on the network (eg, consider the LAN cable is pulled out of the server), then it doesn't look like the thread which is idling, will get terminated. – Abhishek Jun 30 '15 at 12:47
  • Probably because it still doesn't know what happened at the other end. At this time, if there is a call on any of the Store APIs, like isConnected() or close(), the call hits Store.waitIfIdle() and the thread waits there forever. I tried configuring properties for the idle to timeout, but that didn't work either. Maybe as you said, it depends on the JDK/OS to make it to work. – Abhishek Jun 30 '15 at 12:48
  • I fixed some problems in this area for [JavaMail 1.5.4](https://java.net/projects/javamail/pages/Home). Try it and let me know (at javamail_ww@oracle.com) if you're still having this problem. – Bill Shannon Jun 30 '15 at 18:57