Skip to content

Commit afda7b7

Browse files
committed
📚 Add docs for receiver thread & server responses
Most importantly, this documents the scenarios that need extra care to avoid memory leaks: * Commands such as #list or #fetch can have an enormous number of responses. * Commands such as #fetch can result in an enormous size per response. * Long-lived connections will gradually accumulate unsolicited server responses, especially +EXISTS+, +FETCH+, and +EXPUNGE+ responses. * A buggy or untrusted server could send inappropriate responses, which could be very numerous, very large, and very rapid.
1 parent c49ff9e commit afda7b7

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

lib/net/imap.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,37 @@ module Net
126126
#
127127
# This script invokes the FETCH command and the SEARCH command concurrently.
128128
#
129+
# When running multiple commands, care must be taken to avoid ambiguity. For
130+
# example, SEARCH responses are ambiguous about which command they are
131+
# responding to, so search commands should not run simultaneously, unless the
132+
# server supports +ESEARCH+ {[RFC4731]}[https://rfc-editor.org/rfc/rfc4731] or
133+
# IMAP4rev2[https://www.rfc-editor.org/rfc/rfc9051]. See {RFC9051
134+
# §5.5}[https://www.rfc-editor.org/rfc/rfc9051.html#section-5.5] for
135+
# other examples of command sequences which should not be pipelined.
136+
#
137+
# == Unbounded memory use
138+
#
139+
# Net::IMAP reads server responses in a separate receiver thread per client.
140+
# Unhandled response data is saved to #responses, and response_handlers run
141+
# inside the receiver thread. See the list of methods for {handling server
142+
# responses}[rdoc-ref:Net::IMAP@Handling+server+responses], below.
143+
#
144+
# Because the receiver thread continuously reads and saves new responses, some
145+
# scenarios must be careful to avoid unbounded memory use:
146+
#
147+
# * Commands such as #list or #fetch can have an enormous number of responses.
148+
# * Commands such as #fetch can result in an enormous size per response.
149+
# * Long-lived connections will gradually accumulate unsolicited server
150+
# responses, especially +EXISTS+, +FETCH+, and +EXPUNGE+ responses.
151+
# * A buggy or untrusted server could send inappropriate responses, which
152+
# could be very numerous, very large, and very rapid.
153+
#
154+
# Use paginated or limited versions of commands whenever possible.
155+
#
156+
# Use #add_response_handler to handle responses after each one is received.
157+
# Use #extract_responses, #clear_responses, or #responses (with a block) to
158+
# prune responses.
159+
#
129160
# == Errors
130161
#
131162
# An \IMAP server can send three different types of responses to indicate

0 commit comments

Comments
 (0)