6.0.0-alpha14
6/23/25

[#12589] Kolab_Storage: Ensure status($folder) is not cached
Summary Kolab_Storage: Ensure status($folder) is not cached
Queue Horde Framework Packages
Queue Version Git master
Type Bug
State Resolved
Priority 1. Low
Owners slusarz (at) horde (dot) org
Requester thomas.jarosch (at) intra2net (dot) com
Created 08/20/2013 (4325 days ago)
Due
Updated 08/26/2013 (4319 days ago)
Assigned 08/21/2013 (4324 days ago)
Resolved 08/26/2013 (4319 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch Yes

History
08/26/2013 09:18:54 PM Thomas Jarosch Comment #22
Assigned to Michael Slusarz
Taken from Jan Schneider
State ⇒ Resolved
Reply to this comment

[Show Quoted Text - 11 lines]
Alright, you convinced me. Consider the matter solved.

08/23/2013 06:41:50 PM Michael Slusarz Comment #21 Reply to this comment
Thanks! Please take a look at the change again, I think you 
accidentally added the wrong flag.
(STATUS_UIDNEXT_FORCE instead of STATUS_FORCE_REFRESH).
Fixed.
Hmm, I'm still not sure if this is the ideal solution. As you 
pointed out earlier,
this might cause more round trips to the imap server than necessary.
It all depends on your code.
If we look at the search() function for example, in the "long 
running script mode"
it would issue a STATUS command to the server and based on that
result send a SEARCH command or not. In that case it would be better
to just send the SEARCH directly.
No, not necessarily.  At worst if would issue a NOOP.  Otherwise, the 
mailbox needs to be opened anyway for the SEARCH command.  Either way, 
the downside is the potential for sending a NOOP as a way to possibly 
prevent opening the mailbox.  The former is MUCH preferred over the 
latter (opening a mailbox is expensive).
I think for most use-cases of long running scripts, the new
STATUS_FORCE_REFRESH flag will do the job just fine as the
library users can decide when to use caching and when not.
But as you pointed out with vanished(), there's places internally 
where we call status().  A library user would otherwise have no 
control over these calls.  There has to be a way to disable caching so 
that this internal calls don't potentially return different data than 
a status() call with an explicit STATUS_FORCE_REFRESH.
08/23/2013 06:37:08 PM Git Commit Comment #20 Reply to this comment
Changes have been made in Git (master):

commit dd1b0fc6edc26f27ec3386b789edb5de2087e2c7
Author: Michael M Slusarz <slusarz@horde.org>
Date:   Fri Aug 23 12:36:45 2013 -0600

     Fix status flag (Bug #12589)

  .../Imap_Client/lib/Horde/Imap/Client/Base.php     |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

http://git.horde.org/horde-git/-/commit/dd1b0fc6edc26f27ec3386b789edb5de2087e2c7
08/23/2013 07:28:30 AM Thomas Jarosch Comment #19 Reply to this comment
I could see adding something like a global "Long-running script" flag
to the base IMAP object that would indicate that the object is being
used in a long-running script and STATUS_FORCE_REFRESH should be used
on every status() call.
This has been added.  To disable status() caching, 
Horde_Imap_Client_Base:$statuscache should be set to false.
Thanks! Please take a look at the change again, I think you 
accidentally added the wrong flag.
(STATUS_UIDNEXT_FORCE instead of STATUS_FORCE_REFRESH).

Hmm, I'm still not sure if this is the ideal solution. As you pointed 
out earlier,
this might cause more round trips to the imap server than necessary.

If we look at the search() function for example, in the "long running 
script mode"
it would issue a STATUS command to the server and based on that
result send a SEARCH command or not. In that case it would be better
to just send the SEARCH directly.

I think for most use-cases of long running scripts, the new
STATUS_FORCE_REFRESH flag will do the job just fine as the
library users can decide when to use caching and when not.

08/23/2013 06:27:50 AM Michael Slusarz Comment #18 Reply to this comment
I could see adding something like a global "Long-running script" 
flag to the base IMAP object that would indicate that the object is 
being used in a long-running script and STATUS_FORCE_REFRESH should 
be used on every status() call.
This has been added.  To disable status() caching, 
Horde_Imap_Client_Base:$statuscache should be set to false.
08/23/2013 06:25:29 AM Git Commit Comment #17 Reply to this comment
Changes have been made in Git (master):

commit 384ceb2be3ac85dd68cca101718654e41d536030
Author: Michael M Slusarz <slusarz@horde.org>
Date:   Fri Aug 23 00:24:39 2013 -0600

     [mms] Added the 'statuscache' property to Horde_Imap_Client_Base 
(Request #12589).

  .../Imap_Client/doc/Horde/Imap/Client/UPGRADING    |    4 ++++
  .../Imap_Client/lib/Horde/Imap/Client/Base.php     |   17 +++++++++++++++++
  framework/Imap_Client/package.xml                  |    2 ++
  3 files changed, 23 insertions(+), 0 deletions(-)

http://git.horde.org/horde-git/-/commit/384ceb2be3ac85dd68cca101718654e41d536030
08/21/2013 06:16:42 PM Michael Slusarz Comment #16 Reply to this comment
Is that a safe thing to do for a long running script with just one 
selected folder?
I think we need add the STATUS_FORCE_REFRESH flag in case
"current_selected_folder == $mailbox_to_check".
No.  This is the whole reason we are caching in the first place.  We 
might access the status of a single mailbox 5 times in 0.01 seconds in 
a script.  We should absolutely not be issuing 5 NOOP requests for 
something like this.

I could see adding something like a global "Long-running script" flag 
to the base IMAP object that would indicate that the object is being 
used in a long-running script and STATUS_FORCE_REFRESH should be used 
on every status() call.  But most scripts (under a second) don't need 
this.  Issuing NOOPs is expensive and unnecessary.

08/21/2013 05:19:16 PM Thomas Jarosch Comment #15 Reply to this comment
The correct way of fixing this (at least as of Horde_Imap_Client 
2.14.0) will be to add Horde_Imap_Client::STATUS_FORCE_REFRESH to 
the mask passed in the $flags parameter to status().
while debugging an ActiveSync problem, I've noticed that 
Imap_Client::vanished()
internally calls Imap_Client::search(). The search() function internally uses
status() to optimize for empty mailboxes.

Is that a safe thing to do for a long running script with just one 
selected folder?
I think we need add the STATUS_FORCE_REFRESH flag in case
"current_selected_folder == $mailbox_to_check".

There are also other places we call status().
08/21/2013 09:21:46 AM Thomas Jarosch Comment #14 Reply to this comment
I would agree.  Although I will admit that I don't understand the 
original use-cases for these other drivers in the first place.
Kolab pretty early made use of the ANNOTATEMORE extension draft. Back 
in the days you had to patch the c-client library and php to add 
support for it. For distributions that didn't support or want to patch 
their packages, the Net_IMAP pear backend was an alternative (though 
way slower!).

Gunnar kept this concept when he restructured Kolab_Storage though it 
was more of an academic exercise.

08/21/2013 07:47:23 AM Jan Schneider Comment #13 Reply to this comment
@Jan: We should make Horde_Imap_Client mandatory for Kolab_Storage.

The other IMAP backend drivers don't get any testing and I highly doubt
they work properly at all.

In fact I'd like to see them vanish for H5.x / H6: I don't see any 
specific use case in supporting the broken c-client, a Roundcube 
IMAP driver or the unmaintained Net_IMAP pear package.
Yes, I already wanted to do this years ago, but Gunnar liked to keep 
them because they worked at that point. I doubt this is still true, so 
we should get rid of them.
08/21/2013 05:08:18 AM Michael Slusarz Comment #12 Reply to this comment
In fact I would assign the bug to myself but I didn't get my 
developer status back since horde transitioned to git (which was 
ages ago) ;)
FWIW, I have no problems with giving Thomas commit access.

08/21/2013 05:03:53 AM Michael Slusarz Comment #11
State ⇒ Feedback
Reply to this comment
Ok, I've adapted the code to use the new flag. Works fine.
Thanks Michael for implementing it!
Committed.

[Show Quoted Text - 10 lines]
I would agree.  Although I will admit that I don't understand the 
original use-cases for these other drivers in the first place.

08/21/2013 05:02:40 AM Git Commit Comment #10 Reply to this comment
Changes have been made in Git (master):

commit c7bd7f84ee3d788aabb87da3ac8906b41cbd063f
Author: Thomas Jarosch <thomas.jarosch@intra2net.com>
Date:   Tue Aug 20 23:04:11 2013 +0200

     Use new Horde_Imap_Client::STATUS_FORCE_REFRESH flag

     It's more efficient than closing and re-opening the mailbox.

     Bump required Horde_Imap_Client version to 2.14.0.

     Bug #12589

     Signed-off-by: Michael M Slusarz <slusarz@horde.org>

  .../lib/Horde/Kolab/Storage/Driver/Imap.php        |    6 ++----
  framework/Kolab_Storage/package.xml                |    2 +-
  2 files changed, 3 insertions(+), 5 deletions(-)

http://git.horde.org/horde-git/-/commit/c7bd7f84ee3d788aabb87da3ac8906b41cbd063f
08/20/2013 09:14:37 PM Thomas Jarosch Comment #9
New Attachment: 0001-Use-new-Horde_Imap_Client-STATUS_FORCE_REFRESH-flag.patch Download
State ⇒ Assigned
Reply to this comment
Ok, I've adapted the code to use the new flag. Works fine.
Thanks Michael for implementing it!


@Jan: We should make Horde_Imap_Client mandatory for Kolab_Storage.

The other IMAP backend drivers don't get any testing and I highly doubt
they work properly at all.

In fact I'd like to see them vanish for H5.x / H6: I don't see any 
specific use case in supporting the broken c-client, a Roundcube IMAP 
driver or the unmaintained Net_IMAP pear package.

What do you think?

08/20/2013 06:19:39 PM Thomas Jarosch Comment #8 Reply to this comment
The correct way of fixing this (at least as of Horde_Imap_Client 
2.14.0) will be to add Horde_Imap_Client::STATUS_FORCE_REFRESH to 
the mask passed in the $flags parameter to status().
thanks, that's exactly what I was looking for!
(I browsed the Imap_Client source for 30 minutes or so looking for a 
mechanism like this ;))

@mjr: I've only seen this problem with Kolab and only with non-mail 
data. Probably it was triggered because I was only syncing one 
collection and one folder at that time. Otherwise the imap connection 
gets re-used internally and issues SELECT on different folders.

I can look into the proper fix using the new flag probably at the end 
of September, may be earlier.
In fact I would assign the bug to myself but I didn't get my developer 
status back since horde transitioned to git (which was ages ago) ;)

08/20/2013 05:33:58 PM Michael Slusarz Comment #7 Reply to this comment
The correct way of fixing this (at least as of Horde_Imap_Client 
2.14.0) will be to add Horde_Imap_Client::STATUS_FORCE_REFRESH to the 
mask passed in the $flags parameter to status().
08/20/2013 05:32:56 PM Git Commit Comment #6 Reply to this comment
Changes have been made in Git (master):

commit e8c8d319eec4d57e057e285996fddac4a08c1e7c
Author: Michael M Slusarz <slusarz@horde.org>
Date:   Tue Aug 20 11:31:38 2013 -0600

     [mms] Added the Horde_Imap_Client::STATUS_FORCE_REFRESH flag.

     See, e.g., Ticket #12589

  .../Imap_Client/doc/Horde/Imap/Client/UPGRADING    |   10 +++++
  framework/Imap_Client/lib/Horde/Imap/Client.php    |    2 +
  .../Imap_Client/lib/Horde/Imap/Client/Base.php     |   42 ++++++++++++++-----
  framework/Imap_Client/package.xml                  |   12 +++---
  4 files changed, 49 insertions(+), 17 deletions(-)

http://git.horde.org/horde-git/-/commit/e8c8d319eec4d57e057e285996fddac4a08c1e7c
08/20/2013 05:19:27 PM Michael Rubinsky Comment #5 Reply to this comment
While we are talking about this: Thomas, was there something specific 
about Kolab that was causing the status to be stale? I have not seen 
problems with status data being stale during normal syncing 
operations...just wondering if there is something that needs to be 
done in the ActiveSync code to avoid this (fringe?) issue.
08/20/2013 05:13:13 PM Michael Slusarz Comment #4 Reply to this comment
     Ensure the result of status($folder) is not cached by the 
Horde_Imap_Client.
I would rather see this fixed by introducing a separate status flag 
that forces status() to ping the server.  Closing the mailbox is NOT 
the best way to do this - reopening a mailbox is a fairly expensive 
activity.  The correct method would instead to do a NOOP if the 
mailbox is currently open - this will cause the internal cache to be 
updated without having to reopen the mailbox.
08/20/2013 01:39:09 PM Jan Schneider State ⇒ Resolved
Assigned to Jan Schneider
 
08/20/2013 01:38:17 PM Git Commit Comment #3 Reply to this comment
Changes have been made in Git (master):

commit 5df17adcb08d49d05e11897b126dcbfcb1be414d
Author: Jan Schneider <jan@horde.org>
Date:   Tue Aug 20 15:27:19 2013 +0200

     [jan] Retrieve status changes during running requests (Thomas 
Jarosch <thomas.jarosch@intra2net.com>, Bug #12589).

  framework/Kolab_Storage/package.xml |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

http://git.horde.org/horde-git/-/commit/5df17adcb08d49d05e11897b126dcbfcb1be414d
08/20/2013 01:38:13 PM Git Commit Comment #2 Reply to this comment
Changes have been made in Git (master):

commit cb27b7cc468247889f8a594c8090c1206b585de7
Author: Thomas Jarosch <thomas.jarosch@intra2net.com>
Date:   Tue Aug 20 14:29:37 2013 +0200

     Ensure the result of status($folder) is not cached by the 
Horde_Imap_Client.

     Otherwise long running scripts (like ActiveSync polling for changes)
     will see outdated data.

     The close() call does not close the IMAP server socket connection.
     It returns to the authenticated, unselected state.

     Bug 12589

     Signed-off-by: Jan Schneider <jan@horde.org>

  .../lib/Horde/Kolab/Storage/Driver/Imap.php        |    3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)

http://git.horde.org/horde-git/-/commit/cb27b7cc468247889f8a594c8090c1206b585de7
08/20/2013 12:35:47 PM Thomas Jarosch Patch ⇒ Yes
New Attachment: 0001-Ensure-the-result-of-status-folder-is-not-cached.patch Download
 
08/20/2013 12:34:17 PM Thomas Jarosch Comment #1
Priority ⇒ 1. Low
State ⇒ Unconfirmed
Patch ⇒ No
Milestone ⇒
Summary ⇒ Kolab_Storage: Ensure status($folder) is not cached
Type ⇒ Bug
Queue ⇒ Horde Framework Packages
Reply to this comment
From the patch:

Ensure the result of status($folder) is not cached by the Horde_Imap_Client.

Otherwise long running scripts (like ActiveSync polling for changes)
will see outdated data.

The close() call does not close the IMAP server socket connection.
It returns to the authenticated, unselected state.

Saved Queries