[BUG] IMAP hibernation fails on FreeBSD 15.x with "Invalid peer_dev_major value"
Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain
imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Root cause: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros: c
str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino); On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c. Historical context: This was discussed on the Dovecot mailing list in July 2019 (thread: "Hibernation errors") but apparently never resolved upstream. The same failure mode persists in Dovecot 2.4.4. Impact: IMAP hibernation is effectively non-functional on FreeBSD 15.x Processes remain running indefinitely instead of being hibernated Documentation note: The Dovecot 2.4 documentation states that hibernation "is not supported on kqueue based systems currently, such as FreeBSD." However, the code still compiles and attempts to run, producing these errors rather than being disabled at compile time or gracefully skipped at runtime. Would it make sense to either: Disable hibernation at compile time for kqueue systems, or Add validation for major()/minor() return values before serialization? Thanks, Jordan
Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain
imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Root cause: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros: c
str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino);
On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c. Historical context: This was discussed on the Dovecot mailing list in July 2019 (thread: "Hibernation errors") but apparently never resolved upstream. The same failure mode persists in Dovecot 2.4.4. Impact:
o IMAP hibernation is effectively non-functional on FreeBSD 15.x
o Processes remain running indefinitely instead of being hibernated
Documentation note: The Dovecot 2.4 documentation states that hibernation "is not supported on kqueue based systems currently, such as FreeBSD." However, the code still compiles and attempts to run, producing these errors rather than being disabled at compile time or gracefully skipped at runtime. Would it make sense to either:
1. Disable hibernation at compile time for kqueue systems, or
2. Add validation for major()/minor() return values before serialization?
Thanks, Jordan
On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <dovecot@dovecot.org> wrote:
Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain
imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
..
1. Disable hibernation at compile time for kqueue systems, or
It was already supposed to be done, but looks like there's a bug. Can you verify if this works? : diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
Hi Timo, I’ve made freebsd port patch which looks like that: # cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) I’m simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here in the log I see following: Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap(jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate { What we can do more? KR, Jordan
On 25 Jun 2026, at 12:34, Timo Sirainen <timo@sirainen.com> wrote:
On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <dovecot@dovecot.org> wrote:
Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain
imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
..
1. Disable hibernation at compile time for kqueue systems, or
It was already supposed to be done, but looks like there's a bug. Can you verify if this works? :
diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
Hi Timo, i’m not programmer at all but here is my understanding of the problem: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros: str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino); On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c, causing hibernation to fail.
On 25 Jun 2026, at 14:37, Jordan Ostrev <jordan@ostreff.info> wrote:
Hi Timo,
I’ve made freebsd port patch which looks like that:
# cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
I’m simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here
in the log I see following:
Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap(jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate {
What we can do more?
KR, Jordan
On 25 Jun 2026, at 12:34, Timo Sirainen <timo@sirainen.com> wrote:
On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <dovecot@dovecot.org> wrote:
Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain
imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
..
1. Disable hibernation at compile time for kqueue systems, or
It was already supposed to be done, but looks like there's a bug. Can you verify if this works? :
diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
Hi Timo, i'm not programmer at all but here is my understanding of the problem: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros: str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino); On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c, causing hibernation to fail. On 25 Jun 2026, at 14:37, Jordan Ostrev <jordan@ostreff.info> wrote: Hi Timo, I've made freebsd port patch which looks like that: # cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) I'm simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here in the log I see following: Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap(jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate { What we can do more? KR, Jordan On 25 Jun 2026, at 12:34, Timo Sirainen <timo@sirainen.com> wrote: On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <dovecot@dovecot.org> wrote: Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 .. 1. Disable hibernation at compile time for kqueue systems, or It was already supposed to be done, but looks like there's a bug. Can you verify if this works? : diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
Hi, Here is my attempt <https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=286695> to made freebsd port of dovecot 2.4.x software, which i’m using for many years. Currently it builds fine, the only issue i’ve found since now is this imap-hibernate which is definitely not working. Thanks.
On 25 Jun 2026, at 15:50, Jordan Ostrev <jordan@ostreff.info> wrote:
Hi Timo, i’m not programmer at all but here is my understanding of the problem: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros:
str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino);
On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c, causing hibernation to fail.
On 25 Jun 2026, at 14:37, Jordan Ostrev <jordan@ostreff.info> wrote:
Hi Timo,
I’ve made freebsd port patch which looks like that:
# cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
I’m simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here
in the log I see following:
Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap(jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate {
What we can do more?
KR, Jordan
On 25 Jun 2026, at 12:34, Timo Sirainen <timo@sirainen.com> wrote:
On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <dovecot@dovecot.org> wrote:
Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain
imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
..
1. Disable hibernation at compile time for kqueue systems, or
It was already supposed to be done, but looks like there's a bug. Can you verify if this works? :
diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
Hi, Here is my [1]attempt to made freebsd port of dovecot 2.4.x software, which i'm using for many years. Currently it builds fine, the only issue i've found since now is this imap-hibernate which is definitely not working. Thanks. On 25 Jun 2026, at 15:50, Jordan Ostrev <jordan@ostreff.info> wrote: Hi Timo, i'm not programmer at all but here is my understanding of the problem: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros: str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino); On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c, causing hibernation to fail. On 25 Jun 2026, at 14:37, Jordan Ostrev <jordan@ostreff.info> wrote: Hi Timo, I've made freebsd port patch which looks like that: # cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) I'm simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here in the log I see following: Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap(jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate { What we can do more? KR, Jordan On 25 Jun 2026, at 12:34, Timo Sirainen <timo@sirainen.com> wrote: On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <dovecot@dovecot.org> wrote: Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 .. 1. Disable hibernation at compile time for kqueue systems, or It was already supposed to be done, but looks like there's a bug. Can you verify if this works? : diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) References Visible links 1. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=286695
Hi Timo, I am running Dovecot 2.4.4 under FreeBSD 15.x, and I noticed that the IMAP hibernation feature fails to work natively on this platform. The Problem Under FreeBSD, running fstat() on a network socket returns NODEV (UINT64_MAX or 18446744073709551615) for both major()and minor() device numbers. When imap-hibernate tries to serialize these values, they are printed as 64-bit unsigned integers. However, Dovecot's internal parser in imap-master-client.c uses standard 32-bit integers (unsigned int) and str_to_uint(). This causes an integer overflow, triggering the following error during hibernation: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 The Solution I've created a patch for src/imap/imap-master-client.c that scales the parser variables to uint64_t and switches the parsing function to str_to_uint64(). Additionally, it updates the verification assertion to prevent BUG crashes due to the expected dev_tbehavior of virtual network sockets under FreeBSD. Here is the combined patch that fixes the issue completely: Фрагмент от код --- src/imap/imap-master-client.c.orig 2026-05-12 10:48:57 UTC +++ src/imap/imap-master-client.c @@ -75,7 +75,7 @@ imap_master_client_parse_input(const char *const *args const char **error_r) { const char *key, *value; - unsigned int peer_dev_major = 0, peer_dev_minor = 0; + uint64_t peer_dev_major = 0, peer_dev_minor = 0; i_zero(input_r); i_zero(stats_r); @@ -128,13 +128,13 @@ imap_master_client_parse_input(const char *const *args return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { - if (str_to_uint(value, &peer_dev_major) < 0) { + if (str_to_uint64(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { - if (str_to_uint(value, &peer_dev_minor) < 0) { + if (str_to_uint64(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; @@ -265,7 +265,7 @@ imap_master_client_parse_input(const char *const *args } if (peer_dev_major != 0 || peer_dev_minor != 0) { master_input_r->peer_dev = - makedev(peer_dev_major, peer_dev_minor); + makedev((unsigned long)peer_dev_major, (unsigned long)peer_dev_minor); } return 0; } @@ -410,7 +410,8 @@ static int imap_master_client_verify(const struct imap return -1; } if (peer_st.st_ino != master_input->peer_ino || - !CMP_DEV_T(peer_st.st_dev, master_input->peer_dev)) { + (!CMP_DEV_T(peer_st.st_dev, master_input->peer_dev) && + major(peer_st.st_dev) != (unsigned long)-1)) { *error_r = t_strdup_printf( "BUG: Expected peer device=%lu,%lu inode=%s doesn't match " "client fd's actual device=%lu,%lu inode=%s", Result With this patch applied, hibernation works flawlessly under FreeBSD: # doveadm who username # service (pids) (ips) jordan@ostreff.info 1 imap (26000) (46.10.221.52) jordan@ostreff.info 2 imap-hibernate (26260) (46.10.221.52) No error messages are logged by dovecot when it hibernates and restores clients. I hope this can be integrated into the upstream code. Best regards, Jordan
On 25 Jun 2026, at 15:50, Jordan Ostrev <jordan@ostreff.info> wrote:
Hi Timo, i’m not programmer at all but here is my understanding of the problem: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros:
str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino);
On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c, causing hibernation to fail.
On 25 Jun 2026, at 14:37, Jordan Ostrev <jordan@ostreff.info> wrote:
Hi Timo,
I’ve made freebsd port patch which looks like that:
# cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
I’m simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here
in the log I see following:
Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap(jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate {
What we can do more?
KR, Jordan
On 25 Jun 2026, at 12:34, Timo Sirainen <timo@sirainen.com> wrote:
On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <dovecot@dovecot.org> wrote:
Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain
imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615
..
1. Disable hibernation at compile time for kqueue systems, or
It was already supposed to be done, but looks like there's a bug. Can you verify if this works? :
diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
Hi Timo, I am running Dovecot 2.4.4 under FreeBSD 15.x, and I noticed that the IMAP hibernation feature fails to work natively on this platform. The Problem Under FreeBSD, running fstat() on a network socket returns NODEV (UINT64_MAX or 18446744073709551615) for both major()and minor() device numbers. When imap-hibernate tries to serialize these values, they are printed as 64-bit unsigned integers. However, Dovecot's internal parser in imap-master-client.c uses standard 32-bit integers (unsigned int) and str_to_uint(). This causes an integer overflow, triggering the following error during hibernation: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 The Solution I've created a patch for src/imap/imap-master-client.c that scales the parser variables to uint64_t and switches the parsing function to str_to_uint64(). Additionally, it updates the verification assertion to prevent BUG crashes due to the expected dev_tbehavior of virtual network sockets under FreeBSD. Here is the combined patch that fixes the issue completely: Fragment ot kod --- src/imap/imap-master-client.c.orig 2026-05-12 10:48:57 UTC +++ src/imap/imap-master-client.c @@ -75,7 +75,7 @@ imap_master_client_parse_input(const char *const *args const char **error_r) { const char *key, *value; - unsigned int peer_dev_major = 0, peer_dev_minor = 0; + uint64_t peer_dev_major = 0, peer_dev_minor = 0; i_zero(input_r); i_zero(stats_r); @@ -128,13 +128,13 @@ imap_master_client_parse_input(const char *const *args return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { - if (str_to_uint(value, &peer_dev_major) < 0) { + if (str_to_uint64(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { - if (str_to_uint(value, &peer_dev_minor) < 0) { + if (str_to_uint64(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; @@ -265,7 +265,7 @@ imap_master_client_parse_input(const char *const *args } if (peer_dev_major != 0 || peer_dev_minor != 0) { master_input_r->peer_dev = - makedev(peer_dev_major, peer_dev_minor); + makedev((unsigned long)peer_dev_major, (unsigned long)peer_dev_minor); } return 0; } @@ -410,7 +410,8 @@ static int imap_master_client_verify(const struct imap return -1; } if (peer_st.st_ino != master_input->peer_ino || - !CMP_DEV_T(peer_st.st_dev, master_input->peer_dev)) { + (!CMP_DEV_T(peer_st.st_dev, master_input->peer_dev) && + major(peer_st.st_dev) != (unsigned long)-1)) { *error_r = t_strdup_printf( "BUG: Expected peer device=%lu,%lu inode=%s doesn't match " "client fd's actual device=%lu,%lu inode=%s", Result With this patch applied, hibernation works flawlessly under FreeBSD: # doveadm who username # service (pids) (ips) jordan@ostreff.info 1 imap (26000) (46.10.221.52) jordan@ostreff.info 2 imap-hibernate (26260) (46.10.221.52) No error messages are logged by dovecot when it hibernates and restores clients. I hope this can be integrated into the upstream code. Best regards, Jordan On 25 Jun 2026, at 15:50, Jordan Ostrev <jordan@ostreff.info> wrote: Hi Timo, i'm not programmer at all but here is my understanding of the problem: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros: str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino); On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c, causing hibernation to fail. On 25 Jun 2026, at 14:37, Jordan Ostrev <jordan@ostreff.info> wrote: Hi Timo, I've made freebsd port patch which looks like that: # cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) I'm simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here in the log I see following: Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap(jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap(jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap(jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate { What we can do more? KR, Jordan On 25 Jun 2026, at 12:34, Timo Sirainen <timo@sirainen.com> wrote: On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <dovecot@dovecot.org> wrote: Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap(jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 .. 1. Disable hibernation at compile time for kqueue systems, or It was already supposed to be done, but looks like there's a bug. Can you verify if this works? : diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1])
Did you also test that incoming mail, or changes to SELECTed mailboxes is noticed while hibernated? Aki On 25/06/2026 18:34 EEST Jordan Ostrev via dovecot <[1]dovecot@dovecot.org> wrote: Hi Timo, I am running Dovecot 2.4.4 under FreeBSD 15.x, and I noticed that the IMAP hibernation feature fails to work natively on this platform. The Problem Under FreeBSD, running fstat() on a network socket returns NODEV (UINT64_MAX or 18446744073709551615) for both major()and minor() device numbers. When imap-hibernate tries to serialize these values, they are printed as 64-bit unsigned integers. However, Dovecot's internal parser in imap-master-client.c uses standard 32-bit integers (unsigned int) and str_to_uint(). This causes an integer overflow, triggering the following error during hibernation: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 The Solution I've created a patch for src/imap/imap-master-client.c that scales the parser variables to uint64_t and switches the parsing function to str_to_uint64(). Additionally, it updates the verification assertion to prevent BUG crashes due to the expected dev_tbehavior of virtual network sockets under FreeBSD. Here is the combined patch that fixes the issue completely: Fragment ot kod --- src/imap/imap-master-client.c.orig 2026-05-12 10:48:57 UTC +++ src/imap/imap-master-client.c @@ -75,7 +75,7 @@ imap_master_client_parse_input(const char *const *args const char **error_r) { const char *key, *value; - unsigned int peer_dev_major = 0, peer_dev_minor = 0; + uint64_t peer_dev_major = 0, peer_dev_minor = 0; i_zero(input_r); i_zero(stats_r); @@ -128,13 +128,13 @@ imap_master_client_parse_input(const char *const *args return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { - if (str_to_uint(value, &peer_dev_major) < 0) { + if (str_to_uint64(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { - if (str_to_uint(value, &peer_dev_minor) < 0) { + if (str_to_uint64(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; @@ -265,7 +265,7 @@ imap_master_client_parse_input(const char *const *args } if (peer_dev_major != 0 || peer_dev_minor != 0) { master_input_r->peer_dev = - makedev(peer_dev_major, peer_dev_minor); + makedev((unsigned long)peer_dev_major, (unsigned long)peer_dev_minor); } return 0; } @@ -410,7 +410,8 @@ static int imap_master_client_verify(const struct imap return -1; } if (peer_st.st_ino != master_input->peer_ino || - !CMP_DEV_T(peer_st.st_dev, master_input->peer_dev)) { + (!CMP_DEV_T(peer_st.st_dev, master_input->peer_dev) && + major(peer_st.st_dev) != (unsigned long)-1)) { *error_r = t_strdup_printf( "BUG: Expected peer device=%lu,%lu inode=%s doesn't match " "client fd's actual device=%lu,%lu inode=%s", Result With this patch applied, hibernation works flawlessly under FreeBSD: # doveadm who username # service (pids) (ips) [2]jordan@ostreff.info 1 imap (26000) (46.10.221.52) [3]jordan@ostreff.info 2 imap-hibernate (26260) (46.10.221.52) No error messages are logged by dovecot when it hibernates and restores clients. I hope this can be integrated into the upstream code. Best regards, Jordan On 25 Jun 2026, at 15:50, Jordan Ostrev <[4]jordan@ostreff.info> wrote: Hi Timo, i'm not programmer at all but here is my understanding of the problem: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros: str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino); On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c, causing hibernation to fail. On 25 Jun 2026, at 14:37, Jordan Ostrev <[5]jordan@ostreff.info> wrote: Hi Timo, I've made freebsd port patch which looks like that: # cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) I'm simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here in the log I see following: Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap([6]jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap([7]jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap([8]jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap([9]jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap([10]jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap([11]jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap([12]jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap([13]jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate { What we can do more? KR, Jordan On 25 Jun 2026, at 12:34, Timo Sirainen <[14]timo@sirainen.com> wrote: On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <[15]dovecot@dovecot.org> wrote: Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap([16]jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 .. 1. Disable hibernation at compile time for kqueue systems, or It was already supposed to be done, but looks like there's a bug. Can you verify if this works? : diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) Hi Timo, I am running Dovecot 2.4.4 under FreeBSD 15.x, and I noticed that the IMAP hibernation feature fails to work natively on this platform. The Problem Under FreeBSD, running fstat() on a network socket returns NODEV (UINT64_MAX or 18446744073709551615) for both major()and minor() device numbers. When imap-hibernate tries to serialize these values, they are printed as 64-bit unsigned integers. However, Dovecot's internal parser in imap-master-client.c uses standard 32-bit integers (unsigned int) and str_to_uint(). This causes an integer overflow, triggering the following error during hibernation: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 The Solution I've created a patch for src/imap/imap-master-client.c that scales the parser variables to uint64_t and switches the parsing function to str_to_uint64(). Additionally, it updates the verification assertion to prevent BUG crashes due to the expected dev_tbehavior of virtual network sockets under FreeBSD. Here is the combined patch that fixes the issue completely: Fragment ot kod --- src/imap/imap-master-client.c.orig 2026-05-12 10:48:57 UTC +++ src/imap/imap-master-client.c @@ -75,7 +75,7 @@ imap_master_client_parse_input(const char *const *args const char **error_r) { const char *key, *value; - unsigned int peer_dev_major = 0, peer_dev_minor = 0; + uint64_t peer_dev_major = 0, peer_dev_minor = 0; i_zero(input_r); i_zero(stats_r); @@ -128,13 +128,13 @@ imap_master_client_parse_input(const char *const *args return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { - if (str_to_uint(value, &peer_dev_major) < 0) { + if (str_to_uint64(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { - if (str_to_uint(value, &peer_dev_minor) < 0) { + if (str_to_uint64(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; @@ -265,7 +265,7 @@ imap_master_client_parse_input(const char *const *args } if (peer_dev_major != 0 || peer_dev_minor != 0) { master_input_r->peer_dev = - makedev(peer_dev_major, peer_dev_minor); + makedev((unsigned long)peer_dev_major, (unsigned long)peer_dev_minor); } return 0; } @@ -410,7 +410,8 @@ static int imap_master_client_verify(const struct imap return -1; } if (peer_st.st_ino != master_input->peer_ino || - !CMP_DEV_T(peer_st.st_dev, master_input->peer_dev)) { + (!CMP_DEV_T(peer_st.st_dev, master_input->peer_dev) && + major(peer_st.st_dev) != (unsigned long)-1)) { *error_r = t_strdup_printf( "BUG: Expected peer device=%lu,%lu inode=%s doesn't match " "client fd's actual device=%lu,%lu inode=%s", Result With this patch applied, hibernation works flawlessly under FreeBSD: # doveadm who username # service (pids) (ips) [17]jordan@ostreff.info 1 imap (26000) (46.10.221.52) [18]jordan@ostreff.info 2 imap-hibernate (26260) (46.10.221.52) No error messages are logged by dovecot when it hibernates and restores clients. I hope this can be integrated into the upstream code. Best regards, Jordan On 25 Jun 2026, at 15:50, Jordan Ostrev <[19]jordan@ostreff.info> wrote: Hi Timo, i'm not programmer at all but here is my understanding of the problem: In src/imap/imap-client-hibernate.c, the code serializes peer_dev_major and peer_dev_minor using major() and minor() macros: str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev), (unsigned long long)peer_st.st_ino); On FreeBSD, major() and minor() can return UINT64_MAX (18446744073709551615) for file descriptors that are not block/character devices (such as sockets on tmpfs/devfs). This value exceeds UINT_MAX and cannot be parsed by str_to_uint() in imap-master-client.c, causing hibernation to fail. On 25 Jun 2026, at 14:37, Jordan Ostrev <[20]jordan@ostreff.info> wrote: Hi Timo, I've made freebsd port patch which looks like that: # cat files/patch-configure.ac --- configure.ac.orig 2026-06-25 11:03:42 UTC +++ configure.ac @@ -363,7 +363,7 @@ AS_CASE( DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) I'm simulating the situation with telnet: c idle + idling * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here * OK Still here * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * OK Still here d idle c BAD Idle completed. + idling * OK Still here * 4228 EXISTS * 1 RECENT * 4228 EXPUNGE * 0 RECENT * OK Still here * 4228 EXISTS * 4227 FETCH (FLAGS (\Seen $NotJunk NotJunk)) * 4228 EXPUNGE * OK Still here in the log I see following: Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap([21]jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:21:17 classic dovecot[29292]: imap([22]jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap([23]jordan@ostreff.info)<30943><EJZELRJVp5QuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:26:03 classic dovecot[29292]: imap([24]jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:29:28 classic dovecot[29292]: imap([25]jordan@ostreff.info)<29454><CLP/EhJVqIguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:36 classic dovecot[29292]: imap([26]jordan@ostreff.info)<33114><cX5QWRJVrZguCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:33:37 classic dovecot[29292]: imap([27]jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 25 14:34:40 classic dovecot[29292]: imap([28]jordan@ostreff.info)<33112><NlVOWRJVkbEuCt00>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Here is my piece of my config: # dovecot -a | grep hibernate imap_hibernate_timeout = 1 mins service imap-hibernate { unix_listener imap-hibernate { What we can do more? KR, Jordan On 25 Jun 2026, at 12:34, Timo Sirainen <[29]timo@sirainen.com> wrote: On 24. Jun 2026, at 21.34, Jordan Ostrev via dovecot <[30]dovecot@dovecot.org> wrote: Hi, IMAP hibernation compiles and attempts to run on FreeBSD 15.x (tested with Dovecot 2.4.4 and FreeBSD 15.1), but fails at runtime with: plain imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Jun 24 21:27:08 classic dovecot[36888]: imap([31]jordan@ostreff.info)<37120><ExaV/gNVAdt/AAAB>: Error: Couldn't hibernate imap client: /var/run/dovecot/imap-hibernate returned failure: Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 .. 1. Disable hibernation at compile time for kqueue systems, or It was already supposed to be done, but looks like there's a bug. Can you verify if this works? : diff --git a/configure.ac b/configure.ac index 9beacaa299..04f9c8edd6 100644 --- a/configure.ac +++ b/configure.ac @@ -363,7 +363,7 @@ DOVECOT_TYPEOF DOVECOT_IOLOOP DOVECOT_NOTIFY AS_CASE( - ["$notify"], + ["$have_notify"], [none], [BUILD_IMAP_HIBERNATE=0], [kqueue], [BUILD_IMAP_HIBERNATE=0], [BUILD_IMAP_HIBERNATE=1]) _______________________________________________ dovecot mailing list -- [32]dovecot@dovecot.org To unsubscribe send an email to [33]dovecot-leave@dovecot.org References Visible links 1. mailto:dovecot@dovecot.org 2. mailto:jordan@ostreff.info 3. mailto:jordan@ostreff.info 4. mailto:jordan@ostreff.info 5. mailto:jordan@ostreff.info 6. mailto:jordan@ostreff.info 7. mailto:jordan@ostreff.info 8. mailto:jordan@ostreff.info 9. mailto:jordan@ostreff.info 10. mailto:jordan@ostreff.info 11. mailto:jordan@ostreff.info 12. mailto:jordan@ostreff.info 13. mailto:jordan@ostreff.info 14. mailto:timo@sirainen.com 15. mailto:dovecot@dovecot.org 16. mailto:jordan@ostreff.info 17. mailto:jordan@ostreff.info 18. mailto:jordan@ostreff.info 19. mailto:jordan@ostreff.info 20. mailto:jordan@ostreff.info 21. mailto:jordan@ostreff.info 22. mailto:jordan@ostreff.info 23. mailto:jordan@ostreff.info 24. mailto:jordan@ostreff.info 25. mailto:jordan@ostreff.info 26. mailto:jordan@ostreff.info 27. mailto:jordan@ostreff.info 28. mailto:jordan@ostreff.info 29. mailto:timo@sirainen.com 30. mailto:dovecot@dovecot.org 31. mailto:jordan@ostreff.info 32. mailto:dovecot@dovecot.org 33. mailto:dovecot-leave@dovecot.org
Hi Timo,Aki, I have been investigating why the IMAP hibernation feature (imap-hibernate) fails natively under FreeBSD 15.x, and I managed to trace down and fix the core architectural issues. The Root Cause Analysis Integer Overflow on Hibernation Entry: Under FreeBSD 15.x, running fstat() on a network/virtual socket descriptor returns NODEV (UINT64_MAX or 18446744073709551615) for both major() and minor() device numbers. When an IMAP process tries to hibernate, it serializes these values and sends them to the imap-hibernate service. However, both src/imap-hibernate/imap-hibernate-client.c and src/imap/imap-master-client.c utilize 32-bit unsigned int storage for peer_dev_majorand peer_dev_minor, paired with str_to_uint(). This triggers an instant integer overflow parsing error on entry: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 Strict Verification Bug on Unhibernation (Exit): When a client wakes up, imap_master_client_verify() in src/imap/imap-master-client.c checks if the current peer_st.st_dev matches the recorded master_input->peer_dev via the CMP_DEV_T macro. Under FreeBSD, since these are virtual network descriptors, the kernel's device mapping evaluation causes a mismatch check failure, triggering a false positive BUG panic loop during the restore assertion. The Complete 64-bit IPC Solution To resolve this fundamentally without masking data or dropping validation, we need to expand the internal serialization parsers to uint64_t using str_to_uint64() on both ends of the IPC boundary, and add an explicit exemption for FreeBSD's NODEV (-1) sockets during verification. Here are the patches required for a complete solution: 1. Inside src/imap-hibernate/imap-hibernate-client.c --- src/imap-hibernate/imap-hibernate-client.c.orig 2026-06-25 19:49:30 UTC +++ src/imap-hibernate/imap-hibernate-client.c @@ -51,8 +51,7 @@ imap_hibernate_client_parse_input(const char *const *a const char **error_r) { const char *key, *value; - unsigned int peer_dev_major = 0, peer_dev_minor = 0; - + uint64_t peer_dev_major = 0, peer_dev_minor = 0; i_zero(state_r); if (args[0] == NULL) { *error_r = "Missing username in input"; @@ -98,13 +97,13 @@ imap_hibernate_client_parse_input(const char *const *a return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { - if (str_to_uint(value, &peer_dev_major) < 0) { + if (str_to_uint64(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { - if (str_to_uint(value, &peer_dev_minor) < 0) { + if (str_to_uint64(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; @@ -244,7 +243,7 @@ imap_hibernate_client_parse_input(const char *const *a return -1; } if (peer_dev_major != 0 || peer_dev_minor != 0) - state_r->peer_dev = makedev(peer_dev_major, peer_dev_minor); + state_r->peer_dev = makedev((unsigned long)peer_dev_major, (unsigned long)peer_dev_minor); return 0; } 2. Inside src/imap/imap-master-client.c --- src/imap/imap-master-client.c.orig 2026-05-12 10:48:57 UTC +++ src/imap/imap-master-client.c @@ -75,7 +75,7 @@ imap_master_client_parse_input(const char *const *args const char **error_r) { const char *key, *value; - unsigned int peer_dev_major = 0, peer_dev_minor = 0; + uint64_t peer_dev_major = 0, peer_dev_minor = 0; i_zero(input_r); i_zero(stats_r); @@ -128,13 +128,13 @@ imap_master_client_parse_input(const char *const *args return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { - if (str_to_uint(value, &peer_dev_major) < 0) { + if (str_to_uint64(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { - if (str_to_uint(value, &peer_dev_minor) < 0) { + if (str_to_uint64(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; @@ -265,7 +265,7 @@ imap_master_client_parse_input(const char *const *args } if (peer_dev_major != 0 || peer_dev_minor != 0) { master_input_r->peer_dev = - makedev(peer_dev_major, peer_dev_minor); + makedev((unsigned long)peer_dev_major, (unsigned long)peer_dev_minor); } return 0; } @@ -410,7 +410,8 @@ static int imap_master_client_verify(const struct imap return -1; } if (peer_st.st_ino != master_input->peer_ino || - !CMP_DEV_T(peer_st.st_dev, master_input->peer_dev)) { + (!CMP_DEV_T(peer_st.st_dev, master_input->peer_dev) && + major(peer_st.st_dev) != (unsigned long)-1)) { *error_r = t_strdup_printf( "BUG: Expected peer device=%lu,%lu inode=%s doesn't match " "client fd's actual device=%lu,%lu inode=%s", Empirical Testing & Results To answer your question regarding whether incoming mail or flag modifications on SELECTED mailboxes are still properly noticed during background hibernation—yes, I have performed live production tests with these patches applied, and it works perfectly. The Test Scenario: An active connection entered an authenticated session on the INBOX and executed an explicit IDLE sequence. It was successfully sent to sleep and offloaded to imap-hibernate (verified via doveadm who). The Notification Event: A new message was transmitted to the mailbox externally via Gmail. The Outcome: The internal event system seamlessly triggered the kernel notification layers. The imap-hibernateservice immediately picked up the modification event, successfully unhibernated the session, and seamlessly handed the socket descriptor back over to a standard imap worker process. The active client instantly pushed raw streaming updates to the live terminal without dropping connection parameters or printing any errors: Plaintext + idling * OK Still here * 4249 EXISTS * 1 RECENT * 4249 FETCH (FLAGS (\Recent $NotJunk NotJunk)) Long-term stability tests show that idle sessions remain safely tucked away under imap-hibernate for hours until client-side teardowns or standard network NAT lease expirations occur, at which point the process terminates gracefully with a routine Disconnected: Connection closed log record. I hope this native 64-bit conversion can be merged into standard upstream branches to officially unbreak the feature for FreeBSD server deployment. Best regards, Jordan
On 25 Jun 2026, at 19:34, Aki Tuomi <aki.tuomi@open-xchange.com> wrote:
Did you also test that incoming mail, or changes to SELECTed mailboxes is noticed while hibernated?
Hi Timo,Aki, I have been investigating why the IMAP hibernation feature (imap-hibernate) fails natively under FreeBSD 15.x, and I managed to trace down and fix the core architectural issues. The Root Cause Analysis 1. Integer Overflow on Hibernation Entry: Under FreeBSD 15.x, running fstat() on a network/virtual socket descriptor returns NODEV (UINT64_MAX or 18446744073709551615) for both major() and minor() device numbers. When an IMAP process tries to hibernate, it serializes these values and sends them to the imap-hibernate service. However, both src/imap-hibernate/imap-hibernate-client.c and src/imap/imap-master-client.c utilize 32-bit unsigned int storage for peer_dev_majorand peer_dev_minor, paired with str_to_uint(). This triggers an instant integer overflow parsing error on entry: imap-hibernate: Error: conn unix:imap-hibernate (uid=125): Failed to parse client input: Invalid peer_dev_major value: 18446744073709551615 2. Strict Verification Bug on Unhibernation (Exit): When a client wakes up, imap_master_client_verify() in src/imap/imap-master-client.c checks if the current peer_st.st_dev matches the recorded master_input->peer_dev via the CMP_DEV_T macro. Under FreeBSD, since these are virtual network descriptors, the kernel's device mapping evaluation causes a mismatch check failure, triggering a false positive BUG panic loop during the restore assertion. The Complete 64-bit IPC Solution To resolve this fundamentally without masking data or dropping validation, we need to expand the internal serialization parsers to uint64_t using str_to_uint64() on both ends of the IPC boundary, and add an explicit exemption for FreeBSD's NODEV (-1) sockets during verification. Here are the patches required for a complete solution: 1. Inside src/imap-hibernate/imap-hibernate-client.c --- src/imap-hibernate/imap-hibernate-client.c.orig 2026-06-25 19:49:30 UTC +++ src/imap-hibernate/imap-hibernate-client.c @@ -51,8 +51,7 @@ imap_hibernate_client_parse_input(const char *const *a const char **error_r) { const char *key, *value; - unsigned int peer_dev_major = 0, peer_dev_minor = 0; - + uint64_t peer_dev_major = 0, peer_dev_minor = 0; i_zero(state_r); if (args[0] == NULL) { *error_r = "Missing username in input"; @@ -98,13 +97,13 @@ imap_hibernate_client_parse_input(const char *const *a return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { - if (str_to_uint(value, &peer_dev_major) < 0) { + if (str_to_uint64(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { - if (str_to_uint(value, &peer_dev_minor) < 0) { + if (str_to_uint64(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; @@ -244,7 +243,7 @@ imap_hibernate_client_parse_input(const char *const *a return -1; } if (peer_dev_major != 0 || peer_dev_minor != 0) - state_r->peer_dev = makedev(peer_dev_major, peer_dev_minor); + state_r->peer_dev = makedev((unsigned long)peer_dev_major, (unsigned long)peer_dev_minor); return 0; } 2. Inside src/imap/imap-master-client.c --- src/imap/imap-master-client.c.orig 2026-05-12 10:48:57 UTC +++ src/imap/imap-master-client.c @@ -75,7 +75,7 @@ imap_master_client_parse_input(const char *const *args const char **error_r) { const char *key, *value; - unsigned int peer_dev_major = 0, peer_dev_minor = 0; + uint64_t peer_dev_major = 0, peer_dev_minor = 0; i_zero(input_r); i_zero(stats_r); @@ -128,13 +128,13 @@ imap_master_client_parse_input(const char *const *args return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { - if (str_to_uint(value, &peer_dev_major) < 0) { + if (str_to_uint64(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { - if (str_to_uint(value, &peer_dev_minor) < 0) { + if (str_to_uint64(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; @@ -265,7 +265,7 @@ imap_master_client_parse_input(const char *const *args } if (peer_dev_major != 0 || peer_dev_minor != 0) { master_input_r->peer_dev = - makedev(peer_dev_major, peer_dev_minor); + makedev((unsigned long)peer_dev_major, (unsigned long)peer_dev_minor); } return 0; } @@ -410,7 +410,8 @@ static int imap_master_client_verify(const struct imap return -1; } if (peer_st.st_ino != master_input->peer_ino || - !CMP_DEV_T(peer_st.st_dev, master_input->peer_dev)) { + (!CMP_DEV_T(peer_st.st_dev, master_input->peer_dev) && + major(peer_st.st_dev) != (unsigned long)-1)) { *error_r = t_strdup_printf( "BUG: Expected peer device=%lu,%lu inode=%s doesn't match " "client fd's actual device=%lu,%lu inode=%s", Empirical Testing & Results To answer your question regarding whether incoming mail or flag modifications on SELECTED mailboxes are still properly noticed during background hibernation--yes, I have performed live production tests with these patches applied, and it works perfectly. o The Test Scenario: An active connection entered an authenticated session on the INBOX and executed an explicit IDLE sequence. It was successfully sent to sleep and offloaded to imap-hibernate (verified via doveadm who). o The Notification Event: A new message was transmitted to the mailbox externally via Gmail. o The Outcome: The internal event system seamlessly triggered the kernel notification layers. The imap-hibernateservice immediately picked up the modification event, successfully unhibernated the session, and seamlessly handed the socket descriptor back over to a standard imap worker process. The active client instantly pushed raw streaming updates to the live terminal without dropping connection parameters or printing any errors: Plaintext + idling * OK Still here * 4249 EXISTS * 1 RECENT * 4249 FETCH (FLAGS (\Recent $NotJunk NotJunk)) Long-term stability tests show that idle sessions remain safely tucked away under imap-hibernate for hours until client-side teardowns or standard network NAT lease expirations occur, at which point the process terminates gracefully with a routine Disconnected: Connection closed log record. I hope this native 64-bit conversion can be merged into standard upstream branches to officially unbreak the feature for FreeBSD server deployment. Best regards, Jordan On 25 Jun 2026, at 19:34, Aki Tuomi <aki.tuomi@open-xchange.com> wrote: Did you also test that incoming mail, or changes to SELECTed mailboxes is noticed while hibernated?
participants (3)
-
Aki Tuomi
-
Jordan Ostrev
-
Timo Sirainen