Skip to content

Close Two GWeb Request "Bookend" Failure "Holes"

Grant Erickson connman 5 versions – Applied

Status from this message: This series was applied to connman.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest5 patches 0 repliesApplied
  2. v49 patches 3 repliesSuperseded
  3. v318 patches 5 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v222 patches0 repliesSuperseded
v122 patches0 repliesSuperseded

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/5wispr: Refactor 'wispr_portal_web_result' to leverage 'GError'.src/wispr.c+70 -350 replies
2/5wispr: Document 'wispr_portal_web_result_failure'.src/wispr.c+23 -10 replies
3/5wispr: Document 'wispr_portal_web_result_success'.src/wispr.c+21 -20 replies
4/5wispr: Document 'wispr_portal_web_result'.src/wispr.c+30 -00 replies
5/5wispr: Add an optional 'message' parameter to '__connman_wispr_cb_t'.src/connman.h src/service.c src/wispr.c+46 -220 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 0/5] Close Two GWeb Request "Bookend" Failure "Holes"

There existed, prior to this set of changes, two "holes" in the finalization of web request sessions that can (for example, in a client such as WISPr) leave one or both of IPv4 and IPv6 "online" HTTP-based Internet reachability checks "dangling" and non-renewing such that an expected active, default network service failover does not occur when it should.

The first of those two failure "holes" involves an end-of-file (EOF) condition. In the normal case, there are a series of one or more data receipts for the web request as headers and, if present, the body of the request response are fulfilled. When there is no further data to send, the final receive completes with 'g_io_channel_read_chars' returning 'G_IO_STATUS_EOF' status and zero (0) bytes read. This should and does lead to a successful EOF closure of the web request.

However, there is a second EOF case that appears to happen with a random distribution in the nginx server backing the default "online" HTTP-based Internet reachability check URLs, 'ipv[46].connman.net/online/status.html'. In that case, the nginx server appears to periodically do an unexpected and spontaneous remote connection close after the initial connection but before any data has been received.

For WISPr, presently, all such failures hit the same error-handling block which effectively maps such a failure to the effective "null" 'GWEB_HTTP_STATUS_CODE_UNKNOWN' status value. Unfortunately, clients such as WISPr have no way to distinguish this as an actual failure or success and so it lands on the case:

	case GWEB_HTTP_STATUS_CODE_UNKNOWN:
		wispr_portal_context_ref(wp_context);
		__connman_agent_request_browser(wp_context->service,
				wispr_portal_browser_reply_cb,
				wp_context->status_url, wp_context);

which does not "bookend" the original, initiating WISPr web request and leaves the original request "dangling" and non-renewed, eventually leading to the aforementioned "hole" and network service failover failure.

To handle this failure EOF case, if GWeb asked for a non-zero amount of data from 'g_io_channel_read_chars' but received none and has accumulated no headers thus far upon receiving the status 'G_IO_STATUS_EOF', then GWeb assumes that the remote peer server unexpectedly closed the connection, and synthesizes a new GError with the error 'ECONNRESET'. With the addition of the optional, immutable GError parameter to the GWebResult callback function, clients such as WISPr can now distinguish between a HTTP non-response in which no HTTP data was received and one in which HTTP data was received and the status can be disguished by the HTTP status code.

The second of the two failure "holes" involves the case where 'g_io_channel_read_chars' returns 'G_IO_STATUS_ERROR' status. Prior to this change, this funneled to the same "hole" as the 'G_IO_STATUS_ERROR' failure with the same consequence to clients such as WISPr.

To handle this second error case, GWeb now passes a glib GError pointer to 'g_io_channel_read_chars'. If it is set, GWeb passes the GError through to the GWebResult callback function. Otherwise, it synthesizes a GError anew from 'EIO'. As with the failure EOF case, this allows clients to distinguish and handle such failures and to successfully "bookend" their initial web request.

With these changes, WISPr now leverages the newly-added 'GWebResultFunc' GError parameter to refactor 'wispr_portal_web_result' into 'wispr_portal_web_result_failure' and 'wispr_portal_web_result_success' with the former handling non-successful cases and the latter handling successful HTTP status code cases.

With this change, the second, failure EOF case will now return a non-null GError instance from 'GWebResultFunc' and will be handled as a failure by 'wispr_portal_web_result_failure', "bookending" the original "online" HTTP-based Internet reachability check.

All of the prior HTTP status code cases are handled by 'wispr_portal_web_result_success'.

This approachs works within the boundaries of the following constraints:

1. The gio/gio.h header cannot be included in either src/wispr.c or src/service.c since that throws a bunch of symbol conflicts with gdbus/gdbus.h which redefines a number of symbols otherwise defined by gio/gio.h.

2. 'handle_online_check_failure' in src/service.c needs to determine when a check failed due to cancellation.

a. Historically, it looked at 'err == -ECANCELED' from the WISPr
closure callback.

b. However, due to (1), using 'g_error_matches(error, G_IO_ERROR,
G_IO_ERROR_CANCELLED)' instead of 'err == -ECANCELED' cannot be used. So, passing 'const GError *error' all the way through will not work.

3. Some HTTP status codes are failures insofar as WISPr is concerned. The codes are not important, the error messages are.

4. WISPr failure messages need to be logged in src/service.c by 'online_check_log_failure'. A simple null-terminated C string will do.

Grant Erickson (5):
wispr: Refactor 'wispr_portal_web_result' to leverage 'GError'.
wispr: Document 'wispr_portal_web_result_failure'.
wispr: Document 'wispr_portal_web_result_success'.
wispr: Document 'wispr_portal_web_result'.
wispr: Add an optional 'message' parameter to '__connman_wispr_cb_t'.

 src/connman.h |   3 +-
 src/service.c |  61 +++++++++++------
 src/wispr.c   | 184 +++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 189 insertions(+), 59 deletions(-)
Signature · 1 line
2.45.0