pw_software_update: Fix recursive lock acquisition in nanopb service

This commit fixes the same recursive lock acquisition as
I0ee7994fa5e093a05e349876406d0a2bd89fc3e7, in the nanopb software update

The NotifyTransferSucceeded method acquires the same lock, leading to a
recursive lock acquisition. This commit fixes the issue by
by moving the outer lock acquisition into
the if statement that calls SET_ERROR, which is mutually exclusive with
the call to NotifyTransferSucceeded.

Change-Id: I30db9cc47ceca8af5b724018ee8b29cef6fc58cd
Pigweed-Auto-Submit: Eli Lipsitz <>
Reviewed-by: Ali Zhang <>
Commit-Queue: Auto-Submit <>
diff --git a/pw_software_update/ b/pw_software_update/
index 9cc4558..b424fab 100644
--- a/pw_software_update/
+++ b/pw_software_update/
@@ -132,11 +132,11 @@
 Status BundledUpdateService::SetTransferred(const pw_protobuf_Empty&,
                                             BundledUpdateStatus& response) {
-  std::lock_guard lock(mutex_);
   const BundledUpdateState state = status_.acquire()->state;
   if (state != pw_software_update_BundledUpdateState_Enum_TRANSFERRING &&
       state != pw_software_update_BundledUpdateState_Enum_INACTIVE) {
+    std::lock_guard lock(mutex_);
               "SetTransferred() can only be called from TRANSFERRING or "
               "INACTIVE state. State: %d",