-
-
Notifications
You must be signed in to change notification settings - Fork 329
Fix infinite loop in GnuTLS socket I/O when socket blocks #4688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
flatcap
merged 1 commit into
main
from
copilot/fix-16376763-48345674-a15012fe-63df-4972-92d4-6cf828064b81
Nov 10, 2025
Merged
Fix infinite loop in GnuTLS socket I/O when socket blocks #4688
flatcap
merged 1 commit into
main
from
copilot/fix-16376763-48345674-a15012fe-63df-4972-92d4-6cf828064b81
Nov 10, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copilot
AI
changed the title
[WIP] Reproducible freeze with "imap_peek = no" + "color index"
Fix infinite loop in GnuTLS socket I/O when socket blocks
Nov 3, 2025
roccoblues
reviewed
Nov 3, 2025
roccoblues
reviewed
Nov 3, 2025
roccoblues
approved these changes
Nov 3, 2025
Member
roccoblues
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Member
|
@copilot we have failing builds. Please check. |
Author
flatcap
approved these changes
Nov 3, 2025
Member
|
@gahr |
gahr
reviewed
Nov 3, 2025
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
gahr
approved these changes
Nov 3, 2025
Co-authored-by: Dennis Schön <[email protected]> Co-authored-by: Pietro Cerutti <[email protected]> Assisted-by: GitHub Copilot
c54c361 to
9ea1dfe
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix reproducible freeze with "imap_peek = no" + "color index"
Problem
When
imap_peek = nois set and a color index pattern is configured, NeoMutt freezes on "Fetching message..." when a new email arrives.Root Cause
The issue is in
conn/gnutls.cwheregnutls_record_recv(),gnutls_record_send(), andgnutls_handshake()can returnGNUTLS_E_AGAINwhen the socket would block, but the code loops indefinitely without checking if data becomes available.Solution
Modified three locations in
conn/gnutls.cto poll the socket with the configuredsocket_timeoutwhenGNUTLS_E_AGAINis returned:tls_socket_read()- Fixed the main issue affecting message fetchingtls_socket_write()- Applied the same fix for consistencytls_negotiate()- Applied the same fix to the handshake for robustnessImplementation Details
tls_socket_poll_with_timeout()to eliminate code duplicationbool(true = ready, false = timeout/error) for clarityGNUTLS_E_AGAINis returned, the code now polls the socket with timeoutsocket_timeoutconfiguration (default 30 seconds)Testing & Validation
Security Summary
No security vulnerabilities were introduced or discovered during this fix. CodeQL analysis passed with zero alerts.
Original prompt
This section details on the original issue you should resolve
<issue_title>Reproducible freeze with "imap_peek = no" + "color index"</issue_title>
<issue_description>## NeoMutt Version
Expected Behaviour
Continue using NeoMutt after a new email arrives.
Actual Behaviour
When checking email, if a new email arrives, NeoMutt freezes on "Fetching message...".
Steps to Reproduce
Start NeoMutt
Send email to yourself.
Wait about 10 seconds (this is related to the "set timeout" rc config in the minimal rc.
Once the new email is recognized by NeoMutt, then it gets stuck on "Fetching message...".
How often does this happen?
Always
remote (IMAP)
I'm on Ubuntu 25.04.
Here is the debug log (level 1), in case it is useful:
debug-log.txt</issue_description>
<agent_instructions>Try to understand the root cause and prepare a fix.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@flatcap ``` main.c:1758: main (argc=3, argv=0x7fff336703a8, envp=0x7fff336703c8) index/dlg_index.c:1272: dlg_index (dlg=0x973ef10, m_init=0x97526e0) gui/mutt_window.c:608: window_redraw (win=0x9733990) gui/mutt_window.c:570: window_repaint (win=0xa061190) gui/mutt_window.c:564: window_repaint (win=0x9773150) index/index.c:635: index_repaint (win=0x9773150) menu/draw.c:336: menu_redraw_index (menu=0xa072a60) index/dlg_index.c:942: index_color (menu=0xa072a60, line=2530) index/dlg_index.c:1417: email_set_color (m=0x97526e0, e=0xa11dc70) pattern/exec.c:1152: mutt_pattern_exec (pat=0x9758c10, flags=1 '\001', m=0x97526e0, e=0xa11dc70, cache=0x7fff3366fc90) mx.c:1151: mx_msg_open (m=0x97526e0, e=0xa11dc70) imap/message.c:2037: imap_msg_open (m=0x97526e0, msg=0xa182da0, e=0xa11dc70) imap/command.c:1158: imap_cmd_step (adata=0x9766580) conn/socket.c:245: mutt_socket_readln_d(buf=0x973d210 "a0050 OK Fetch completed (0.006 + 0.000 + 0.005 secs).", buflen=512, conn=0x973bef0, dbg=5) conn/socket.c:206: mutt_socket_readchar(conn=0x973bef0, c=0x7fff3366f6d3 "\t") conn/zstrm.c:147: zstrm_read (conn=0x973bef0, buf=0x973c194 "F..."..., len=1024) conn/gnutls.c:1061: tls_socket_read (conn=0x978d640, buf=0x9790da0 "\273...", count=8192) ```It gets stuck in
tls_socket_read().gnutls_record_recv()times out and returnsGNUTLS_E_AGAIN, so we keep looping.</comment_new><comment_new>@scottkosty
Thanks for figuring that out! Let me know if there's any other testing I can do that would be helpful.</comment_new>
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.