zwoop commented on code in PR #13151: URL: https://github.com/apache/trafficserver/pull/13151#discussion_r3222870643
########## src/iocore/aio/unit_tests/test_AIOCallback.cc: ########## @@ -0,0 +1,67 @@ +/** @file + + Catch based unit tests for AIOCallback. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include <catch2/catch_test_macros.hpp> + +#include "iocore/aio/AIO.h" +#include "iocore/eventsystem/Event.h" + +namespace +{ + +struct AIOCompletionOwner : Continuation { + AIOCallback callback; + bool *completed = nullptr; + + explicit AIOCompletionOwner(bool &completion_flag) : Continuation(nullptr), completed(&completion_flag) + { + SET_HANDLER(&AIOCompletionOwner::handle_aio_complete); + + callback.action = this; + callback.aiocb.aio_nbytes = 0; + callback.aio_result = 0; + } + + int + handle_aio_complete(int event, void *data) + { + CHECK(event == AIO_EVENT_DONE); + CHECK(data == &callback); + + *completed = true; + delete this; + return EVENT_DONE; + } +}; + +} // namespace + +TEST_CASE("AIOCallback completion tolerates owner deletion", "[iocore][aio]") +{ + bool completed = false; + auto owner = new AIOCompletionOwner(completed); + auto callback = &owner->callback; + + CHECK(callback->io_complete(EVENT_NONE, nullptr) == EVENT_DONE); Review Comment: Somewhat interesting thought from Claude, a comment may be useful? Again, nitpick. ``` The test only catches the regression under ASan/MSan. The owner is destroyed inside handle_aio_complete, so on broken code the post-dispatch if (from_api) reads freed memory — but since from_api == false by default, the branch happens to be skipped and the test passes. Without sanitizers, this test would not have caught the original bug. The CI runs ASan, so this is acceptable, but consider noting it in a comment so someone running the test locally without ASan understands why a passing result isn't conclusive. Even better: also assert the from_api == true path (e.g., a second test where the owner does not delete itself and the callback is dynamically allocated with from_api = true, verifying the snapshot still triggers the self-delete). ` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
