timer: fix uv_timer_start on closing timer

Return `UV_EINVAL` in this case.

Fixes: https://github.com/libuv/libuv/issues/2416
PR-URL: https://github.com/libuv/libuv/pull/2424
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
seny 2019-08-13 15:07:24 -07:00 committed by Santiago Gimeno
parent fa41f13444
commit 2ee2d4622a
No known key found for this signature in database
GPG Key ID: F28C3C8DA33C03BE
3 changed files with 16 additions and 1 deletions

View File

@ -74,7 +74,7 @@ int uv_timer_start(uv_timer_t* handle,
uint64_t repeat) {
uint64_t clamped_timeout;
if (cb == NULL)
if (uv__is_closing(handle) || cb == NULL)
return UV_EINVAL;
if (uv__is_active(handle))

View File

@ -197,6 +197,7 @@ TEST_DECLARE (timer_huge_timeout)
TEST_DECLARE (timer_huge_repeat)
TEST_DECLARE (timer_run_once)
TEST_DECLARE (timer_from_check)
TEST_DECLARE (timer_is_closing)
TEST_DECLARE (timer_null_callback)
TEST_DECLARE (timer_early_check)
TEST_DECLARE (idle_starvation)
@ -729,6 +730,7 @@ TASK_LIST_START
TEST_ENTRY (timer_huge_repeat)
TEST_ENTRY (timer_run_once)
TEST_ENTRY (timer_from_check)
TEST_ENTRY (timer_is_closing)
TEST_ENTRY (timer_null_callback)
TEST_ENTRY (timer_early_check)

View File

@ -292,6 +292,19 @@ TEST_IMPL(timer_run_once) {
}
TEST_IMPL(timer_is_closing) {
uv_timer_t handle;
ASSERT(0 == uv_timer_init(uv_default_loop(), &handle));
uv_close((uv_handle_t *)&handle, NULL);
ASSERT(UV_EINVAL == uv_timer_start(&handle, never_cb, 100, 100));
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(timer_null_callback) {
uv_timer_t handle;