Skip to content

Commit a6b803b

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 b848e71 commit a6b803b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/net/imap.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,37 @@ module Net
207207
#
208208
# This script invokes the FETCH command and the SEARCH command concurrently.
209209
#
210+
# When running multiple commands, care must be taken to avoid ambiguity. For
211+
# example, SEARCH responses are ambiguous about which command they are
212+
# responding to, so search commands should not run simultaneously, unless the
213+
# server supports +ESEARCH+ {[RFC4731]}[https://rfc-editor.org/rfc/rfc4731] or
214+
# IMAP4rev2[https://www.rfc-editor.org/rfc/rfc9051]. See {RFC9051
215+
# §5.5}[https://www.rfc-editor.org/rfc/rfc9051.html#section-5.5] for
216+
# other examples of command sequences which should not be pipelined.
217+
#
218+
# == Unbounded memory use
219+
#
220+
# Net::IMAP reads server responses in a separate receiver thread per client.
221+
# Unhandled response data is saved to #responses, and response_handlers run
222+
# inside the receiver thread. See the list of methods for {handling server
223+
# responses}[rdoc-ref:Net::IMAP@Handling+server+responses], below.
224+
#
225+
# Because the receiver thread continuously reads and saves new responses, some
226+
# scenarios must be careful to avoid unbounded memory use:
227+
#
228+
# * Commands such as #list or #fetch can have an enormous number of responses.
229+
# * Commands such as #fetch can result in an enormous size per response.
230+
# * Long-lived connections will gradually accumulate unsolicited server
231+
# responses, especially +EXISTS+, +FETCH+, and +EXPUNGE+ responses.
232+
# * A buggy or untrusted server could send inappropriate responses, which
233+
# could be very numerous, very large, and very rapid.
234+
#
235+
# Use paginated or limited versions of commands whenever possible.
236+
#
237+
# Use #add_response_handler to handle responses after each one is received.
238+
# Use #extract_responses, #clear_responses, or #responses (with a block) to
239+
# prune responses.
240+
#
210241
# == Errors
211242
#
212243
# An \IMAP server can send three different types of responses to indicate

0 commit comments

Comments
 (0)