Skip to content

potential issue with worker.release_dep #2420

Closed

Description

@tjb900

Hi!

Bringing this up here to get some feedback on how you think it should be handled - I'm happy to write a fix but obviously don't want to go in a direction that won't be accepted.

We are working in an adaptive-scaling environment, and are hitting a race condition where sometimes workers don't have what the scheduler thinks they have - and thus frees data that it shouldn't. After a lot of time spent tracing and digging, this is, I think what is happening:

  1. something (e.g. a client, or a future dependent task which is not yet eligible) needs task1 to be kept alive
  2. worker1 computes task1 (state: memory)
  3. worker2 starts work on a task2 which depends on task1. It obtains the dependency from worker1, and tells the scheduler (
    self.batched_stream.send({'op': 'add-keys',
    or
    self.batched_stream.send({'op': 'add-keys',
    ) that it has it (this notification can be delayed, however).
  4. we try to scale the cluster down, and (for whatever reason) decide to close worker1. The scheduler sees that both worker1 and worker2 have task1, and so does not make a copy anywhere else.
  5. worker1 closes; scheduler now has task1.who_has = {worker2}.
  6. worker2 then completes task2, and frees the dependency (task1) (in release_dep), and tells the scheduler that it freed it (but again, this notification can be delayed)
  7. when the notification arrives at the scheduler that worker2 has released task1, it causes it to be recomputed (if it can be - if task1 was scattered data this would then be an error).

I added a log message to worker.py to see occurrences of these:

@@ -939,6 +939,13 @@ class Worker(ServerNode):
                 if k in self.actors:
                     from .actor import Actor
                     data[k] = Actor(type(self.actors[k]), self.address, k)
+                else:
+                    logger.warning(
+                        "peer %s asked me for key %s but I don't have it!",
+                        str(comm.peer_address),
+                        str(k))
+                    for rel in [l for l in self.log if k in l]:
+                        logger.warning("relevant log entry: %s", str(rel))
 
         msg = {'status': 'OK',
                'data': {k: to_serialize(v) for k, v in data.items()}}

leading to thousands of messages like (edited):

2018-12-15 15:31:26,180  46221:MainThread                    WARNING distributed.worker :: peer tcp://xxxx asked me for key YYY but I don't have it!
2018-12-15 15:31:26,182  46221:MainThread                    WARNING distributed.worker :: relevant log entry: ("YYY", 'new-dep', 'waiting')
2018-12-15 15:31:26,183  46221:MainThread                    WARNING distributed.worker :: relevant log entry: ('dep', "YYY", 'waiting', 'flight')
2018-12-15 15:31:26,184  46221:MainThread                    WARNING distributed.worker :: relevant log entry: ("YYY", 'release-dep')

As a test/fix I have commented out the lines linked above where the worker tells the scheduler that it has a task that it obtained as a dependency. Put another way, the worker does not tell the scheduler about tasks it has in memory, unless it plans to keep them.

@@ -1226,8 +1233,8 @@ class Worker(ServerNode):
             if self.dependents[dep]:
                 self.dep_state[dep] = 'memory'
                 self.put_key_in_memory(dep, value)
-                self.batched_stream.send({'op': 'add-keys',
-                                          'keys': [dep]})
+                #self.batched_stream.send({'op': 'add-keys',
+                #                          'keys': [dep]})
             else:
                 self.release_dep(dep)
 
@@ -1642,9 +1649,9 @@ class Worker(ServerNode):
 
                 self.log.append(('receive-dep', worker, list(response['data'])))
 
-                if response['data']:
-                    self.batched_stream.send({'op': 'add-keys',
-                                              'keys': list(response['data'])})
+                #if response['data']:
+                #    self.batched_stream.send({'op': 'add-keys',
+                #                              'keys': list(response['data'])})
             except EnvironmentError as e:
                 logger.exception("Worker stream died during communication: %s",
                                  worker)

With this patch, the above errors are not triggered at all in a many-hours-long run.

Is that an acceptable solution to this problem? If not, what direction would you like the solution to take?

Activity

  1. mrocklin commented on Dec 17, 2018

    @mrocklin
    Member

    I'll take a closer look at this tomorrow, but I wanted to quickly raise a question with this line:

    worker2 then completes task2, and frees the dependency (task1) (in release_dep), and tells the scheduler that it freed it

    My current understanding is that this doesn't happen. Instead, worker2 tells the scheduler that it has completed task2, the scheduler then makes a determination of whether or not worker2 should free task1. Given that a client wants this data I don't see why the scheduler would make this decision.

    But, I haven't yet read through everything you've written (just making a cursory pass over things after getting home and before heading to bed).

    Regardless, thank you for the effort to raise this cleanly and for the detailed explanation.

  2. tjb900 commented on Dec 17, 2018

    @tjb900
    ContributorAuthor

    Thanks for the reply @mrocklin . Indeed, I'm not yet 100% sure what precipitates the release-dep - a task completing was just my natural assumption. I will take another look at the code and continue investigating.

  3. tjb900 commented on Dec 17, 2018

    @tjb900
    ContributorAuthor

    OK... I see what you mean. I thought I had convinced myself that the worker was unilaterally releasing data that was only gathered due to a dependency, but I see that that's not the case.

    I've tweaked some of the internal log entries so that the "relevant log entries" search works a little better. Does this sound more plausible?

    1. worker2 requests dependency task1 (log: request-dep) for task2, taking it into flight state
    2. gather_dep yields into get_data_from_worker, relinquishing control so other events can happen
    3. While we are waiting for the transfer, task2 is released before it runs - the reason for this is something I am still chasing up, but it might have something to do with rescheduling/stealing
    4. In release_key, the dependency is released because it is still in flight
      self.release_dep(dep)
      This means that it is removed from in_flight_tasks
    5. When gather_dep resumes, task1 has arrived, and this is immediately reported to the scheduler here (
      self.batched_stream.send({'op': 'add-keys',
      ). However, it is never stored in memory (normally done here
      self.transition_dep(d, 'memory', value=data[d])
      ) because it is not in in_flight_tasks/in_flight_workers.
  4. mrocklin commented on Dec 17, 2018

    @mrocklin
    Member

    Yes you're right, that does seems suspicious, and could lead to errors like you suggest.

    There doesn't seem to be a yield between the add-keys line and the transition_dep(..., 'memory') line, so we should be able to move things around pretty easily. Is this a change you would be interesting in submitting?

    Also, I'm impressed at your ability to investigate the scheduling code. It's not an easy system to dive into :)

  5. added 2 commits that reference this issue on May 2, 2019
    713c23d
    5dd0020
  6. jrbourbeau commented on Jul 3, 2019

    @jrbourbeau
    Member

    I've had users report coming across similar behavior. Namely a worker whose story for a particular key ends with a "receive-dep" entry, but doesn't have a "put-in-memory" entry. Unfortunately, this behavior it's completely deterministic and constructing a test to reproduce the issue has been hard to come by.

    The proposed changes in #2421 are to remove

    if response["data"]:
    self.batched_stream.send(
    {"op": "add-keys", "keys": list(response["data"])}
    )

    where the scheduler is informed the worker has keys before they are loaded into worker memory. With this change, informing the scheduler should take place after the keys have been loaded into memory when transition_dep_flight_memory is called. @mrocklin do you have any thoughts on the proposed changes? Does this seem like a reasonable path forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions