Subject: bug#18116: 24.3.92; url-http calls CALLBACK recursively with malformed CBARGS if the former calls `delete-process'

From: Stefan Monnier <[email-masked]>
Date: Tue, 09 Sep 2014 22:24:46 -0400

> (require 'url-http)
> (defvar uht-counter 0)
> (defun uht-callback (status)
>   (declare (special url-http-process))
>   (message "%s %s" uht-counter status)
>   (delete-process url-http-process))
> (defun uht-test ()
>   (setq uht-counter (1+ uht-counter))
>   ;; The port must not be open.
>   (url-http (url-generic-parse-url "http://localhost:3333") #'uht-callback (list 'foo)))

[ Thanks a lot Óscar for bisecting this one.  ]

Dmitry, could you explain a bit more of the context?

The problem is that calling `delete-process' may run the sentinel (and
since this is code run from the sentinel, it may end up calling the
sentinel recursively).

So if you don't want the sentinel to be called recursively, you'll want
to (set-process-sentinel url-http-process nil) before calling
delete-process (or refrain from calling delete-process).

> If the callback expects STATUS to contain some specific data structure,
> that can cause breakage, see https://github.com/marijnh/tern/issues/350
> for an example.

The format looks normal: the STATUS is expected to be a plist holding
the "history" of the connection.  It can contain various ":error FOO"
and ":redirect BAR" entries.

I think the problem comes from a doc error, where url-http points to
url-retrieve for the doc of CBARGS, whereas it uses the format of
url-retrieve-internal instead.

        Stefan