diff --git a/master/buildbot/process/buildstep.py b/master/buildbot/process/buildstep.py
index <HASH>..<HASH> 100644
--- a/master/buildbot/process/buildstep.py
+++ b/master/buildbot/process/buildstep.py
@@ -129,6 +129,8 @@ class SyncLogFileWrapper(logobserver.LogObserver):
         self.finished = False
         self.finishDeferreds = []
 
+        self.step._sync_addlog_deferreds.append(addLogDeferred)
+
         @addLogDeferred.addCallback
         def gotAsync(log):
             self.asyncLogfile = log
@@ -537,6 +539,7 @@ class BuildStep(results.ResultComputingConfigMixin,
     def run(self):
         self._start_deferred = defer.Deferred()
         unhandled = self._start_unhandled_deferreds = []
+        self._sync_addlog_deferreds = []
         try:
             # here's where we set things up for backward compatibility for
             # old-style steps, using monkey patches so that new-style steps
@@ -571,6 +574,9 @@ class BuildStep(results.ResultComputingConfigMixin,
                 self._start_deferred.callback(results)
             results = yield self._start_deferred
         finally:
+            # wait all the sync logs have been actually created before finishing
+            yield defer.DeferredList(self._sync_addlog_deferreds,
+                                     consumeErrors=True)
             self._start_deferred = None
             unhandled = self._start_unhandled_deferreds
             self._start_unhandled_deferreds = None
wait for the logs are created before finishing the step

There is a race condition between addLogs calls, and the end of the step.

for oldStyleSteps, this matters, because the subsequent addStderr, are only called
at the end of the step, so we must wait for log are created before continuing