From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Tiphaine Turpin <tiphaine.turpin@inria.fr>
Cc: 10815@debbugs.gnu.org
Subject: bug#10815: counterintuitive results with process-send-string
Date: Thu, 23 Feb 2012 00:05:43 -0500 [thread overview]
Message-ID: <jwvpqd6w41g.fsf-monnier+gnus-read-ephemeral-bug@gnu.org> (raw)
In-Reply-To: <4F3B837D.4050506@inria.fr> (Tiphaine Turpin's message of "Wed, 15 Feb 2012 11:05:49 +0100")
severity 10815 important
thanks
> Here is a very short extract from my code (exact code, no simplification):
> (message "sending command %s" c)
> (process-send-string connection
> (concat request-start "\n" c "\n" end-of-message
> "\n"))
> (message "command sent: %s" c)
> and an extract of the resulting *Messages* (I have replaced the real
> "command" contents by timestamps):
> sending command 1
> sending command 2
> command sent: 2
> sending command 3
> command sent: 3
> command sent: 1
This output is not a problem in itself, it can be explained as follows:
- (message "sending command %s" 1)
- (process-send-string connection .... 1)
- after sending the command we check timers and process filters; turns
out we received an answer from the process so we run the filter.
- (message "sending command %s" 2)
- (process-send-string connection .... 2)
- (message "command sent: %s" 2)
- before returning from process-send-string, we check timers and filters
once more and find another answer, so we run the filter again.
- (message "sending command %s" 3)
- (process-send-string connection .... 3)
- (message "command sent: %s" 3)
- finally the timers and filters seem all processed, we can return.
- (message "command sent: %s" 1)
> The other end of the socket connection receives the messages in the order 2,
> 3, 1, i.e., the same as indicated by "comment sent" debug messages.
That is more problematic. I haven't looked enough at the code to see
exactly why it happens, but I agree it's undesirable.
> It seems that process-send-string,although it is blocking (until sent data
> is acknowledged), may allow execution of other code (which in this case
> calls process-send-string again). This seems to be allowed by its
> specification: "Output from processes can arrive in between bunches.",
Indeed, but it doesn't justify the kind of out-of-order-sending you're
seeing (although it may explain it).
> except that in my setting, I am almost sure than no input can be available
> at this moment, at least from this connection.
Are you sure: consider the case where the OS forces Emacs to yield right
after sending the bytes, such that the other process gets to reply
before Emacs finishes the process-send-string?
Of course, rather than process filters, the culprit might be a timer.
> In fact, the calls to process-send-string are initiated by
> after-modify hooks, originating from a single user command (which
> performs several modifications).
Can they also be triggered from timers? I.e. is there some timer code
modifying the buffer? Or does the process-filter itself modify the
buffer (seems unlikely since it would lead to inf-loops)?
> But what is really annoying, is that the inner call to process-send-string
> takes priority on the pending one: the second message is actually sent
> before the first, while I would expect the messages to be queued in the
> right order.
Yes, that seems to be a bug/misfeature.
Stefan
next prev parent reply other threads:[~2012-02-23 5:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-15 10:05 bug#10815: counterintuitive results with process-send-string Tiphaine Turpin
2012-02-15 11:00 ` Andreas Schwab
2012-02-23 5:05 ` Stefan Monnier [this message]
2012-03-26 15:26 ` bug#10815: #10815 " Troels Nielsen
2012-06-17 9:00 ` Chong Yidong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvpqd6w41g.fsf-monnier+gnus-read-ephemeral-bug@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=10815@debbugs.gnu.org \
--cc=tiphaine.turpin@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).