-
Notifications
You must be signed in to change notification settings - Fork 1.6k
pubsub - modify_ack_deadline does not work, message gets redelivered after 10 minutes always #4648
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
Comments
@sachin-shetty Could you try with |
Also, I'm not 100% sure how the line subscriber.modify_ack_deadline(sname, [pubsub_message._ack_id], 120) will interact with the lease management thread (i.e. the one that is logging "Renewing lease for ...") but that seems to be the problem. The "expected" usage pattern would be that you assume your callback only need the state of the pubsub_message.modify_ack_deadline(120.0) |
Hi @dhermes Tried new version as well as pubsub_message.modify_ack_deadline. Same result. Message gets re-delivered in exactly 10 minutes even after calling pubsub_message.modify_ack_deadline(120) every minute. and even though pubsub_message.modify_ack_deadline(120) is called, debug logs still show 10s
|
I tried commenting _start_lease_worker() in subscriber/policy/thread.py, that stopped the lease worker from forcing a 10s ack deadline. but the message sent to server by the subscriber.modify_ack_deadline(sname, [pubsub_message._ack_id], 120) still shows as 10s in the debug logs. I see that 10s is hardcoded in base.py Is there a version I can downgrade to to get this to work, I need longer message ack time. |
I'm fairly certain this is a bug. The lease maintenance thread is trying to make sure a deadline gets extended for any messages that the subscriber is still responsible for, but in doing this extension it actually reduces the lease time for your message (this is a mistake in your and my opinion). There is no equivalent high-throughput / highly concurrent implementation you can downgrade to. Here is every Pub / Sub release. Version |
Thankyou @dhermes. Do you think a potential fix would be available anytime soon? I am trying to figure out if I should build application level logic to handle this or wait for a fix. |
actually 0.27.0 docs are still available at http://temp.theadora.io/google-cloud-python-pubsub-0-27/pubsub/usage.html |
@explicitcall Thanks for the link, but be aware that the |
@dhermes are there any plans to host documentation for multiple versions on the official docs site? That would be greatly appreciated. |
@explicitcall No concrete plans, but I have ideas in my head once we can split |
Blocked by #4325? |
@sachin-shetty This is a known server-side bug. There are two that have rolled out server side this week. You should see a lot less of this issue, but it might recur to an extent. There is a relatively straightforward workaround -- let me know if things are not any better for you (literally) starting today. Thanks for your patience! |
@dhermes Let's keep this one open since if we don't solve this completely server-side, we'll need to address the use case some other way -- e.g. through documentation on explicit limits and alternatives. Also: the receipt acks bug/FR will make this worse. So we may need to fix that to call this fixed. |
I am still not able to the extend an acknowledgement using the google-cloud-pubsub==0.30.1 library. Can you please recommend a workaround? |
@kir-titievsky . I tried with 0.30.1, still cannot get the message to be renewed after 10 minutes, irrespective of any number of callbacks to modify_ack_deadline. My test script:
Output:
Message gets redelivered at 10th minute. Please let me know of any workaround, this is a blocker for us. |
Hi - @kir-titievsky - can you please let me know the workaround? |
Sachin, The code below worked for me with no duplicates. I have a vague subscription that your error handling at the very bottom might be to blame for your results: the underlying code occasionally surfaces exceptions that come from closed connections. The code will rebuild the connection automatically. You, however, close the client and rebuild it -- which stops all renewals. Try catching only specific exception types maybe? import google.cloud.pubsub_v1 as pubsub from google.cloud import exceptions import time import logging,logging.handlers from datetime import datetime import sys,os subscriber = pubsub.SubscriberClient() sname = 'projects/google.com:kir-learns-cloud/subscriptions/sachin' def timestamp(): return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) def create_topic(project_id, topic_name): publisher = pubsub.PublisherClient() topic_path = publisher.topic_path(project_id, topic_name) publish_future = publisher.publish(topic_path, 'Published at: %s ' % timestamp()) # wait for the publish to succeed logging.warn("PUB : %s at %s", publish_future.result(), timestamp()) def callback(pubsub_message): logging.warn("PULL: %s %s at %s", pubsub_message.message_id, pubsub_message.data, timestamp()) time.sleep(60*12) logging.warn("ACK : %s %s at %s", pubsub_message.message_id, pubsub_message.data, timestamp()) pubsub_message.ack() if __name__ == '__main__': project = 'google.com:kir-learns-cloud' create_topic(project, 'sachin') subscriber = pubsub.SubscriberClient() subscriber.subscribe("projects/%s/subscriptions/%s"%(project, "sachin"), callback=callback) while True: time.sleep(10) |
@kir-titievsky - Sorry no luck, with your script, I get duplicates at 10 minutes WARNING:root:PUB : 27133513131810 at 2018-01-24 11:06:50 I only changed the project and topic in your script.
I also tried this from a US server to see if that makes any difference, no luck. @SeanMaday - can you please try with the script provided by @kir-titievsky since you are also hitting the same issue. |
This could be a fluke, so worth trying with a few messages. If that does
not work, you can try doing this with an older version of the client
library [0] which uses a polling pull method. You would do something like:
Let me know if and how this works out for you. And thanks for your patience.
…--------
import multiprocessing
from google.cloud import pubsub
def run(topic_name='parser-jobs'):
"""Receives a message from a pull subscription."""
pubsub_client = pubsub.Client()
topic = pubsub_client.topic(topic_name)
subscription = topic.subscription(topic_name)
results = subscription.pull(return_immediately=False, max_messages=1)
ack_id, message = results.pop()
file_name = message.data.strip('"').strip()
if not (file_name.startswith('gs://') and file_name.endswith('.gz')):
subscription.acknowledge((ack_id,))
log('Skipping following file because it does not look like a GCS
URL ' + message.data)
return 1
log('Starting work on file %s' % file_name)
parse_process = multiprocessing.Process(target=parse, args=(file_name,))
parse_process.start()
while parse_process.is_alive():
time.sleep(CHECK_INTERVAL_SEC)
subscription.modify_ack_deadline((ack_id,), 2 * CHECK_INTERVAL_SEC)
subscription.acknowledge((ack_id,))
return 0
--------
[0] https://pypi.org/project/google-cloud-pubsub/0.27.0/ . Don't remember
which pip or easyinstall command let's you specify the version of the top
of my head unfortunately.
You can build similar logic with the API client library
<https://developers.google.com/api-client-library/python/apis/pubsub/v1>
which have a lower level API, but are maintained so should not suffer from
version conflicts (if you run into those).
On Wed, Jan 24, 2018 at 6:32 AM, Sachin Shetty ***@***.***> wrote:
@kir-titievsky <https://github.com/kir-titievsky> - Sorry no luck, with
your script, I get duplicates at 10 minutes
WARNING:root:PUB : 27133513131810 at 2018-01-24 11:06:50
WARNING:root:PULL: 27133513131810 Published at: 2018-01-24 11:06:50 at
2018-01-24 11:06:51
WARNING:root:PULL: 27133513131810 Published at: 2018-01-24 11:06:50 at
2018-01-24 11:16:49
WARNING:root:ACK : 27133513131810 Published at: 2018-01-24 11:06:50 at
2018-01-24 11:18:51
I only changed the project and topic in your script.
< sname = 'projects/google.com:kir-learns-cloud/subscriptions/sachin'
---
> #sname = 'projects/google.com:kir-learns-cloud/subscriptions/sachin'
> sname = 'projects/audit-bq/subscriptions/ack-test-topic-subscribe'
> tname = 'projects/audit-bq/topics/ack-test-topic'
28,29c30,31
< project = 'google.com:kir-learns-cloud'
< create_topic(project, 'sachin')
---
> project = 'audit-bq'
> create_topic(project, 'ack-test-topic')
31c33
< subscriber.subscribe("projects/%s/subscriptions/%s"%(project, "sachin"), callback=callback)
---
> subscriber.subscribe(sname, callback=callback)
I also tried this from a US server to see if that makes any difference, no
luck.
@SeanMaday <https://github.com/seanmaday> - can you please try with the
script provided by @kir-titievsky <https://github.com/kir-titievsky>
since you are also hitting the same issue.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4648 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ARrMFoRc6JBOLKXHIz3e1yVkryUr4MoYks5tNxTmgaJpZM4RJV0p>
.
--
Kir Titievsky | Product Manager | Google Cloud Pub/Sub
<https://cloud.google.com/pubsub/overview>
|
Thankyou @kir-titievsky. I tested 0.27 and it looks better, I am able to hold on to a message longer as long as I keep renewing it. BTW, even nack does not work in 0.31, I fetched a messages, nacked it at 8th minute, the message got immediately redelivered - which is good, but it again got redelivered at 10th minute - so something is really funky about 10 minutes in 0.31. |
@sachin-shetty Sachin, 10 minutes is a magical number in that it's the maximum duration for which you can modifyAckDeadline. To keep the messages longer, you have to repeatedly call modifyAckDeadline. Were you doing that? @dhermes Is there something that the client library does at 10 min intervals? |
Yes, I tried modifyAckDeadline on both message and subscription I have switched to 0.27 which is working well for me. |
@kir-titievsky the pydoc says "This is not an extension", which is quite deceiving if this function can be called to indeed "extend" the deadline. |
Juan, fair point. Any interest in submitting a small PR to correct this?
…On Thu, Feb 1, 2018 at 1:14 PM Juan M Uys ***@***.***> wrote:
@kir-titievsky <https://github.com/kir-titievsky> the pydoc
<https://github.com/GoogleCloudPlatform/google-cloud-python/blob/8616c45291e999ad83b8b45fe16d990f73cbed0f/pubsub/google/cloud/pubsub_v1/subscriber/message.py#L233-L236>
says "This is not an extension", which is quite deceiving if this function
can be called to indeed "extend" the deadline.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4648 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ARrMFs2tL6yoP5J0fxfjXbfDn-Z9ZVk9ks5tQf8cgaJpZM4RJV0p>
.
--
Kir Titievsky | Product Manager | Google Cloud Pub/Sub
<https://cloud.google.com/pubsub/overview>
|
Nevermind. You sent a PR already. |
Given that #4822 is merged, what work remains for this issue? |
I think this is fine to close. We can always re-open or file a new issue. |
Uh oh!
There was an error while loading. Please reload this page.
General, Core, and Other are also allowed as types
google-cloud-pubsub - 0.29.2
Linux 4.4.0-104-generic Set up local machine test automation with tox. #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
python --version
Python 2.7.12
pip show google-cloud
,pip show google-<service>
orpip freeze
google-cloud: 0.30.0
google-cloud-pubsub - 0.29.2
I need to have very long ack deadlines since our consumer process could be running for long time per message. No matter what I set as ack_deadline_seconds in subscription definition, or call subscriber.modify_ack_deadline every 1 minute, the message gets redelivered in exact ten minutes.
I have a test case with a simple subscriber::
enabling DEBUG logging, I see ack messages every few seconds
DEBUG:google.cloud.pubsub_v1.subscriber.policy.base:The current p99 value is 10 seconds.
DEBUG:google.cloud.pubsub_v1.subscriber.policy.base:Renewing lease for 5 ack IDs.
DEBUG:google.cloud.pubsub_v1.subscriber.policy.base:Snoozing lease management for 7.362112 seconds.
DEBUG:google.cloud.pubsub_v1.subscriber._consumer:Sending request:
but message gets redelivered in 10 minutes.
Using GitHub flavored markdown can help make your request clearer.
See: https://guides.github.com/features/mastering-markdown/
The text was updated successfully, but these errors were encountered: