forked from nginx/unit
-
Notifications
You must be signed in to change notification settings - Fork 1
fix(io): generalize PR #54 write-path contract to non-TLS sites (P3) #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andypost
wants to merge
1
commit into
master
Choose a base branch
from
p3-write-path-non-tls
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58
−9
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -746,9 +746,28 @@ nxt_port_read_handler(nxt_task_t *task, void *obj, void *data) | |
| b = nxt_port_buf_alloc(port); | ||
|
|
||
| if (nxt_slow_path(b == NULL)) { | ||
| /* TODO: disable event for some time */ | ||
| /* | ||
| * Buffer pool exhausted (transient OOM on port mem_pool). | ||
| * Falling through would dereference b->mem.pos and crash; | ||
| * mirror PR #54's contract by disarming the read event and | ||
| * routing through the orderly error path. No timer | ||
| * infrastructure exists for ports, so re-arm depends on | ||
| * the port being torn down via nxt_port_error_handler. | ||
| * | ||
| * Recovery via timer-driven retry was rejected as out of | ||
| * P3 scope; terminal teardown is the strict improvement | ||
| * over the pre-P3 NULL-deref. | ||
| */ | ||
| nxt_alert(task, "port{%d,%d} %d: buf alloc failed; " | ||
| "disabling read", | ||
| (int) port->pid, (int) port->id, port->socket.fd); | ||
| nxt_fd_event_block_read(task->thread->engine, &port->socket); | ||
| goto fail; | ||
| } | ||
|
|
||
| /* Invariant past the OOM teardown above; aids future audits. */ | ||
| nxt_assert(b != NULL); | ||
|
|
||
| iov[0].iov_base = &msg.port_msg; | ||
| iov[0].iov_len = sizeof(nxt_port_msg_t); | ||
|
|
||
|
|
@@ -889,9 +908,31 @@ nxt_port_queue_read_handler(nxt_task_t *task, void *obj, void *data) | |
| b = nxt_port_buf_alloc(port); | ||
|
|
||
| if (nxt_slow_path(b == NULL)) { | ||
| /* TODO: disable event for some time */ | ||
| /* | ||
| * Buffer pool exhausted (transient OOM on port mem_pool). | ||
| * Falling through would dereference b->mem.pos in either the | ||
| * dequeue memcpy or the iov[1] recv branch. Mirror PR #54's | ||
| * contract: disarm the read event, decrement the queue | ||
| * counter, and route through the orderly error handler. | ||
| * | ||
| * Recovery via timer-driven retry was rejected as out of | ||
| * P3 scope; terminal teardown is the strict improvement | ||
| * over the pre-P3 NULL-deref. | ||
| */ | ||
| nxt_alert(task, "port{%d,%d} %d: buf alloc failed; " | ||
| "disabling read", | ||
| (int) port->pid, (int) port->id, port->socket.fd); | ||
|
Comment on lines
+922
to
+924
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The format specifiers in the
This also removes the need for casting the arguments. nxt_alert(task, "port{%PI,%uD} %d: buf alloc failed; "
"disabling read",
port->pid, port->id, port->socket.fd); |
||
| nxt_fd_event_block_read(task->thread->engine, &port->socket); | ||
| nxt_atomic_fetch_add(&queue->nitems, -1); | ||
| nxt_work_queue_add(&task->thread->engine->fast_work_queue, | ||
| nxt_port_error_handler, task, &port->socket, | ||
| NULL); | ||
| return; | ||
| } | ||
|
|
||
| /* Invariant past the OOM teardown above; aids future audits. */ | ||
| nxt_assert(b != NULL); | ||
|
|
||
| if (n >= (ssize_t) sizeof(nxt_port_msg_t)) { | ||
| nxt_memcpy(&msg.port_msg, qmsg, sizeof(nxt_port_msg_t)); | ||
|
|
||
|
|
@@ -1342,7 +1383,15 @@ nxt_port_error_handler(nxt_task_t *task, void *obj, void *data) | |
| nxt_port_send_msg_t *msg; | ||
|
|
||
| nxt_debug(task, "port error handler %p", obj); | ||
| /* TODO */ | ||
| /* | ||
| * The bare TODO here historically asked for richer error context | ||
| * (e.g. surfacing the actual socket.error to peers). Investigated | ||
| * for P3 (write-path contract): the handler already drains all | ||
| * queued send messages, releases buffers, and decrements port | ||
| * refcounts. No silent success or NULL-deref bug is hidden here; | ||
| * adding richer error responses is a future enhancement and not | ||
| * part of PR #54's write-path contract. | ||
| */ | ||
|
|
||
| port = nxt_container_of(obj, nxt_port_t, socket); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format specifiers in the
nxt_alertcall should be updated for correctness and consistency:%PIshould be used fornxt_pid_t(port->pid).%uDshould be used foruint32_t(port->id) to avoid potential overflow when casting to a signedint.This also removes the need for casting the arguments.