Skip to content

Commit

Permalink
fix bug by completing the PR DeviceFarmer#650 (DeviceFarmer#824)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis barbaron <[email protected]>
  • Loading branch information
denis99999 authored and michal-murin committed Jan 28, 2025
1 parent 31353dd commit 90838bf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/units/api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function addUserDevice(req, res) {

datautil.normalize(device, req.user)
if (!deviceutil.isAddable(device, req.user)) {
lockutil.unlockDevice(lock)
return res.status(403).json({
success: false
, description: 'Device is being used or not available'
Expand All @@ -147,6 +148,7 @@ function addUserDevice(req, res) {
// Timer will be called if no JoinGroupMessage is received till 5 seconds
var responseTimer = setTimeout(function() {
req.options.channelRouter.removeListener(wireutil.global, messageListener)
lockutil.unlockDevice(lock)
return res.status(504).json({
success: false
, description: 'Device is not responding'
Expand All @@ -158,6 +160,7 @@ function addUserDevice(req, res) {
if (message.serial === serial && message.owner.email === req.user.email) {
clearTimeout(responseTimer)
req.options.channelRouter.removeListener(wireutil.global, messageListener)
lockutil.unlockDevice(lock)

return res.json({
success: true
Expand Down Expand Up @@ -191,13 +194,10 @@ function addUserDevice(req, res) {
)
])
}
return false
})
.catch(function(err) {
apiutil.internalError(res, `Failed to take control of ${serial} device: `, err.stack)
})
.finally(function() {
lockutil.unlockDevice(lock)
apiutil.internalError(res, `Failed to take control of ${serial} device: `, err.stack)
})
}

Expand Down

0 comments on commit 90838bf

Please sign in to comment.