Commit c634d747 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

fix delete channel with long polling subscribers

parent 0cf6b62c
......@@ -101,6 +101,13 @@ ngx_http_push_stream_delete_unrecoverable_channels(ngx_http_push_stream_shm_data
ngx_queue_remove(&cur->queue);
ngx_shmtx_unlock(&shpool->mutex);
if (subscriber->longpolling) {
ngx_http_push_stream_add_polling_headers(subscriber->request, ngx_time(), 0, subscriber->request->pool);
ngx_http_send_header(subscriber->request);
ngx_http_push_stream_send_response_content_header(subscriber->request, ngx_http_get_module_loc_conf(subscriber->request, ngx_http_push_stream_module));
}
ngx_http_push_stream_send_response_message(subscriber->request, channel, channel->channel_deleted_message);
break;
......@@ -108,7 +115,7 @@ ngx_http_push_stream_delete_unrecoverable_channels(ngx_http_push_stream_shm_data
}
// subscriber does not have any other subscription, the connection may be closed
if (ngx_queue_empty(&subscriber->subscriptions_sentinel.queue)) {
if (subscriber->longpolling || ngx_queue_empty(&subscriber->subscriptions_sentinel.queue)) {
ngx_http_push_stream_send_response_finalize(subscriber->request);
}
}
......
......@@ -500,4 +500,36 @@ class TestSubscriberLongPolling < Test::Unit::TestCase
add_test_timeout
}
end
def config_test_delete_channel_with_long_polling_subscriber
@publisher_mode = 'admin'
@message_template = '{\"id\":\"~id~\", \"message\":\"~text~\", \"channel\":\"~channel~\"}'
end
def test_delete_channel_with_long_polling_subscriber
headers = {'accept' => 'application/json'}
body = 'published message'
channel = 'ch_test_delete_channel_with_long_polling_subscriber'
resp = ""
EventMachine.run {
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 30
sub_1.callback {
assert_equal(200, sub_1.response_header.status, "Wrong status")
response = JSON.parse(sub_1.response)
assert_equal(channel, response["channel"], "Wrong channel")
assert_equal(-2, response["id"].to_i, "Wrong channel")
EventMachine.stop
}
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers, :timeout => 30
pub.callback {
assert_equal(200, pub.response_header.status, "Request was not received")
assert_equal(0, pub.response_header.content_length, "Should response only with headers")
assert_equal("Channel deleted.", pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
}
add_test_timeout
}
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment