Thanks. Perhaps an alternative would be for me to create a child context with a deadline of (context - x seconds) and pass that to OtherService, with the expectation that there should be x seconds left over for the write to spanner.
On Wed, Aug 15, 2018 at 8:10 PM Dave Cheney <d...@cheney.net> wrote: > > > On Thursday, 16 August 2018 12:15:57 UTC+10, r...@google.com wrote: >> >> As an example: >> Client calls MyService with a deadline of 10 seconds. >> MyService calls OtherService as part of responding. However, the call to >> OtherService times out due to the deadline in 10 seconds. >> MyService tries to log the error to Spanner; but it's still using that >> context deadline which expired. >> >> Is there a way to get a new context with an extended deadline? Are there >> any issues with that approach? >> > > Sure, just call context.WithDeadline(context.Background()) and use that > instead > > The difficulty is you want the deadline of this new context to live > beyond its parent. Logically it feels like this new context is subordinate > to the previous, but by design we've said that the new context is _not_ > subordinate -- the deadline does not apply to it. I think you need to > address this incongruousness before proceeding. > > >> >> >> On Tuesday, August 14, 2018 at 1:25:47 PM UTC-7, r...@google.com wrote: >>> >>> I'm working on a service that write some log info to spanner when it's >>> done responding to a request. >>> However, the service uses the context's deadline to write to spanner, so >>> if the deadline expires due to some long running RPC, the write to spanner >>> fails (because the deadline expired), and we don't get any log info. >>> >>> What's the best practice for dealing with this situation? >>> >> -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/TUicHyvYNX0/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.