(geronimo-mail) 01/05: GERONIMO-6901 - harden the failed-open unwind: deselect a successfully selected mailbox before pooling the connection
[email protected] Sat, 18 Jul 2026 19:12:27 +0000
| Newsgroups | gmane.comp.java.geronimo.cvs |
|---|---|
| Message-ID | <[email protected]> |
This is an automated email from the ASF dual-hosted git repository. rzo1 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/geronimo-mail.git commit 30c7fc621616c317ee51678fe68a6c808b674765 Author: Richard Zowalla <[email protected]> AuthorDate: Sat Jul 18 20:54:38 2026 +0200 GERONIMO-6901 - harden the failed-open unwind: deselect a successfully selected mailbox before pooling the connection Follow-up from review: on the ReadOnlyFolderException sub-path the SELECT succeeded, so the unwind returned a pooled connection with the mailbox still selected. Track selection state and issue a best-effort CLOSE before releasing. Also guard removeResponseHandler so an unexpected failure cannot skip releaseFolderConnection. --- .../org/apache/geronimo/mail/store/imap/IMAPFolder.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/IMAPFolder.java b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/IMAPFolder.java index 52dfcbc..e36a292 100644 --- a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/IMAPFolder.java +++ b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/IMAPFolder.java @@ -651,6 +651,9 @@ public class IMAPFolder extends Folder implements UIDFolder, IMAPUntaggedRespons // record our open mode this.mode = mode; + // tracks whether SELECT/EXAMINE succeeded, so the failure unwind knows + // if the connection still has a mailbox attached + boolean mailboxSelected = false; try { IMAPMailboxStatus status; @@ -675,6 +678,7 @@ public class IMAPFolder extends Folder implements UIDFolder, IMAPUntaggedRespons } throw e; } + mailboxSelected = true; // not available in the requested mode? if (status.mode != mode) { @@ -729,8 +733,19 @@ public class IMAPFolder extends Folder implements UIDFolder, IMAPUntaggedRespons } catch (MessagingException e) { // ignore...we're already on a failure path here. } - conn.removeResponseHandler(this); + if (mailboxSelected) { + try { + // the SELECT/EXAMINE itself succeeded (e.g. the + // ReadOnlyFolderException path), so the mailbox is still + // selected; deselect so the connection goes back to the + // pool without a live mailbox attached. + conn.closeMailbox(); + } catch (MessagingException e) { + // ignore...we're already on a failure path here. + } + } try { + conn.removeResponseHandler(this); ((IMAPStore)store).releaseFolderConnection(this, conn); } catch (MessagingException e) { // ignore...we're already on a failure path here.