I have a fleet of devices connected to a different openBalena instance than the devices originally registered on (background here). Most devices have upgraded to new releases (4 images in each) that were deployed to this server and are reporting state information. The remaining devices are “online” and “have internet connectivity”, and create a lot of logs like the following. Any advice for how to debug this?
INSERT INTO "image install" ("device", "installs-image", "install date", "download progress", "status", "is provided by-release")
SELECT "image install"."device", "image install"."installs-image", "image install"."install date", "image install"."download progress", "image install"."status", "image install"."is provided by-release"
FROM (
SELECT "image install"."created at", "image install"."modified at", "image install"."device", "image install"."installs-image", "image install"."id", "image install"."install date", "image install"."download progress", "image install"."status", "image install"."is provided by-release"
FROM (
SELECT CAST(NULL AS TIMESTAMP) AS "created at", CAST(NULL AS TIMESTAMP) AS "modified at", CAST($1 AS INTEGER) AS "device", CAST($2 AS INTEGER) AS "installs-image", CAST(NULL AS INTEGER) AS "id", CAST($3 AS TIMESTAMP) AS "install date", CAST($4 AS INTEGER) AS "download progress", CAST($5 AS VARCHAR(255)) AS "status", CAST($6 AS INTEGER) AS "is provided by-release"
) AS "image install"
WHERE EXISTS (
SELECT 1
FROM "device" AS "image install.device"
WHERE "image install"."device" = "image install.device"."id"
AND (("image install.device"."actor") IS NOT NULL AND ("image install.device"."actor") = ($7)
OR EXISTS (
SELECT 1
FROM "device" AS "image install.device.is managed by-device"
WHERE "image install.device"."is managed by-device" = "image install.device.is managed by-device"."id"
AND ("image install.device.is managed by-device"."actor") IS NOT NULL AND ("image install.device.is managed by-device"."actor") = ($7)
))
)
AND EXISTS (
SELECT 1
FROM "image" AS "image install.installs-image"
WHERE "image install"."installs-image" = "image install.installs-image"."id"
AND EXISTS (
SELECT 1
FROM "image-is part of-release" AS "image install.installs-image.image-is part of-release"
WHERE "image install.installs-image"."id" = "image install.installs-image.image-is part of-release"."image"
AND EXISTS (
SELECT 1
FROM "release" AS "im install.installs-im.im-is par of-rel.is part of-release"
WHERE "image install.installs-image.image-is part of-release"."is part of-release" = "im install.installs-im.im-is par of-rel.is part of-release"."id"
AND EXISTS (
SELECT 1
FROM "application" AS "arxwle$l.installs-im.im-is par of-rel.is par of-rel.bel to-appl"
WHERE "im install.installs-im.im-is par of-rel.is part of-release"."belongs to-application" = "arxwle$l.installs-im.im-is par of-rel.is par of-rel.bel to-appl"."id"
AND (EXISTS (
SELECT 1
FROM "device" AS "ppae5y$lls-im.im-is par of-rel.is par of-rel.bel to-appl.ow-dev"
WHERE "arxwle$l.installs-im.im-is par of-rel.is par of-rel.bel to-appl"."id" = "ppae5y$lls-im.im-is par of-rel.is par of-rel.bel to-appl.ow-dev"."belongs to-application"
AND ("ppae5y$lls-im.im-is par of-rel.is par of-rel.bel to-appl.ow-dev"."actor") IS NOT NULL AND ("ppae5y$lls-im.im-is par of-rel.is par of-rel.bel to-appl.ow-dev"."actor") = ($7)
)
OR ("arxwle$l.installs-im.im-is par of-rel.is par of-rel.bel to-appl"."is public") IS NOT NULL AND ("arxwle$l.installs-im.im-is par of-rel.is par of-rel.bel to-appl"."is public") = ($8)
OR ("arxwle$l.installs-im.im-is par of-rel.is par of-rel.bel to-appl"."is host") IS NOT NULL AND ("arxwle$l.installs-im.im-is par of-rel.is par of-rel.bel to-appl"."is host") = ($9))
)
)
)
)
) AS "image install" [ 61, 5, 2022-05-11T01:16:46.578Z, null, 'Downloaded', 2, 122, 1, 1 ]
[... SKIPPING IDENTICAL SQL, #2 ...]
) AS "image install" [ 61, 6, 2022-05-11T01:16:46.578Z, null, 'Downloaded', 2, 122, 1, 1 ]
[... SKIPPING IDENTICAL SQL, #3 ...]
) AS "image install" [ 61, 7, 2022-05-11T01:16:46.578Z, null, 'Downloaded', 2, 122, 1, 1 ]
[... SKIPPING IDENTICAL SQL, #4 ...]
) AS "image install" [ 61, 8, 2022-05-11T01:16:46.578Z, null, 'Downloaded', 2, 122, 1, 1 ]
[... SKIPPING IDENTICAL SQL, #5 ...]
) AS "image install" [ 61, 801, 2022-05-11T01:16:46.578Z, null, 'exited', 253, 122, 1, 1 ]
[... SKIPPING IDENTICAL SQL, #6 ...]
) AS "image install" [ 61, 802, 2022-05-11T01:16:46.578Z, null, 'Running', 253, 122, 1, 1 ]
[... SKIPPING IDENTICAL SQL, #7 ...]
) AS "image install" [ 61, 803, 2022-05-11T01:16:46.578Z, null, 'Running', 253, 122, 1, 1 ]
[... SKIPPING IDENTICAL SQL, #8 ...]
) AS "image install" [ 61, 804, 2022-05-11T01:16:46.578Z, null, 'Running', 253, 122, 1, 1 ]
Parsing GET /resin/device?$filter=(id in (61)) and (os_version eq null)&$select=id,is_of__device_type
Parsing GET /resin/device?$filter=(id in (61)) and (supervisor_version eq null)&$select=id&$expand=is_of__device_type($select=is_of__cpu_architecture,id)
Running GET /resin/device?$filter=(id in (61)) and (os_version eq null)&$select=id,is_of__device_type
Running GET /resin/device?$filter=(id in (61)) and (supervisor_version eq null)&$select=id&$expand=is_of__device_type($select=is_of__cpu_architecture,id)
SELECT "device"."id", "device"."is of-device type" AS "is_of__device_type"
FROM (
SELECT "device"."created at", "device"."modified at", "device"."id", "device"."actor", "device"."api heartbeat state", "device"."uuid", "device"."local id", "device"."device name", "device"."note", "device"."is of-device type", "device"."belongs to-application", "device"."is online", "device"."last connectivity event", "device"."is connected to vpn", "device"."last vpn event", "device"."is locked until-date", "device"."logs channel", "device"."public address", "device"."vpn address", "device"."ip address", "device"."mac address", "device"."memory usage", "device"."memory total", "device"."storage block device", "device"."storage usage", "device"."storage total", "device"."cpu usage", "device"."cpu temp", "device"."is undervolted", "device"."cpu id", "device"."is running-release", "device"."download progress", "device"."status", "device"."os version", "device"."os variant", "device"."supervisor version", "device"."provisioning progress", "device"."provisioning state", "device"."api port", "device"."api secret", "device"."is managed by-service instance", "device"."should be running-release", "device"."should be operated by-release", "device"."is managed by-device", "device"."should be managed by-release", 0 AS "is web accessible", CASE
WHEN ("device"."status" IN ('Ordered', 'Preparing')
OR "device"."is online" = 0
AND "device"."status" = 'Shipped') THEN LOWER("device"."status")
WHEN 1 = 0 THEN 'inactive'
WHEN "device"."provisioning state" = 'Post-Provisioning' THEN 'post-provisioning'
WHEN "device"."is online" = 0
AND "device"."api heartbeat state" IN ('offline', 'unknown')
AND "device"."last connectivity event" IS NULL THEN 'configuring'
WHEN "device"."is online" = 0
AND "device"."api heartbeat state" IN ('offline', 'unknown') THEN 'offline'
WHEN "device"."download progress" IS NOT NULL
AND "device"."status" = 'Downloading' THEN 'updating'
WHEN "device"."provisioning progress" IS NOT NULL THEN 'configuring'
WHEN EXISTS (
SELECT 1
FROM "image install"
WHERE "image install"."device" = "device"."id"
AND "image install"."download progress" IS NOT NULL
AND "image install"."status" = 'Downloading'
) THEN 'updating'
ELSE 'idle'
END AS "overall status", CASE
WHEN ("device"."status" IN ('Ordered', 'Preparing')
OR "device"."is online" = 0
AND "device"."status" = 'Shipped'
OR 1 = 0) THEN NULL
WHEN "device"."provisioning state" = 'Post-Provisioning' THEN "device"."provisioning progress"
WHEN "device"."is online" = 0
AND "device"."api heartbeat state" IN ('offline', 'unknown')
AND "device"."last connectivity event" IS NULL THEN "device"."provisioning progress"
WHEN "device"."is online" = 0
AND "device"."api heartbeat state" IN ('offline', 'unknown') THEN NULL
WHEN "device"."download progress" IS NOT NULL
AND "device"."status" = 'Downloading' THEN "device"."download progress"
WHEN "device"."provisioning progress" IS NOT NULL THEN "device"."provisioning progress"
WHEN EXISTS (
SELECT 1
FROM "image install"
WHERE "image install"."device" = "device"."id"
AND "image install"."download progress" IS NOT NULL
AND "image install"."status" = 'Downloading'
) THEN (
SELECT CAST(ROUND(AVG(COALESCE("image install"."download progress", 100))) AS INTEGER)
FROM "image install"
WHERE "image install"."device" = "device"."id"
AND "image install"."status" != 'deleted'
AND ("image install"."status" = 'Downloading'
OR "image install"."is provided by-release" = COALESCE("device"."should be running-release", (
SELECT "application"."should be running-release"
FROM "application"
WHERE "device"."belongs to-application" = "application"."id"
)))
)
ELSE NULL
END AS "overall progress"
FROM "device"
WHERE (("device"."actor") IS NOT NULL AND ("device"."actor") = ($1)
OR EXISTS (
SELECT 1
FROM "device" AS "device.is managed by-device"
WHERE "device"."is managed by-device" = "device.is managed by-device"."id"
AND (("device.is managed by-device"."actor") IS NOT NULL AND ("device.is managed by-device"."actor") = ($1)
OR EXISTS (
SELECT 1
FROM "device" AS "device.is managed by-device.is managed by-device"
WHERE "device.is managed by-device"."is managed by-device" = "device.is managed by-device.is managed by-device"."id"
AND 1 = 0
)
OR EXISTS (
SELECT 1
FROM "application" AS "device.is managed by-device.belongs to-application"
WHERE "device.is managed by-device"."belongs to-application" = "device.is managed by-device.belongs to-application"."id"
AND EXISTS (
SELECT 1
FROM "application" AS "dev.is managed by-dev.bel to-appl.depends on-application"
WHERE "device.is managed by-device.belongs to-application"."depends on-application" = "dev.is managed by-dev.bel to-appl.depends on-application"."id"
AND EXISTS (
SELECT 1
FROM "device" AS "dev.is managed by-dev.bel to-appl.depends on-appl.owns-device"
WHERE "dev.is managed by-dev.bel to-appl.depends on-application"."id" = "dev.is managed by-dev.bel to-appl.depends on-appl.owns-device"."belongs to-application"
AND ("dev.is managed by-dev.bel to-appl.depends on-appl.owns-device"."actor") IS NOT NULL AND ("dev.is managed by-dev.bel to-appl.depends on-appl.owns-device"."actor") = ($1)
)
)
))
)
OR EXISTS (
SELECT 1
FROM "application" AS "device.belongs to-application"
WHERE "device"."belongs to-application" = "device.belongs to-application"."id"
AND EXISTS (
SELECT 1
FROM "application" AS "device.belongs to-application.depends on-application"
WHERE "device.belongs to-application"."depends on-application" = "device.belongs to-application.depends on-application"."id"
AND EXISTS (
SELECT 1
FROM "device" AS "dev.belongs to-application.depends on-application.owns-device"
WHERE "device.belongs to-application.depends on-application"."id" = "dev.belongs to-application.depends on-application.owns-device"."belongs to-application"
AND ("dev.belongs to-application.depends on-application.owns-device"."actor") IS NOT NULL AND ("dev.belongs to-application.depends on-application.owns-device"."actor") = ($1)
)
)
))
) AS "device"
WHERE "device"."id" IN ($2)
AND "device"."os version" IS NULL [ 122, 61 ]
SELECT (
SELECT coalesce(array_to_json(array_agg("device.is of-device type".*)), '[]') AS "is_of__device_type"
FROM (
SELECT "device.is of-device type"."is of-cpu architecture" AS "is_of__cpu_architecture", "device.is of-device type"."id"
FROM (
SELECT "device type"."created at", "device type"."modified at", "device type"."id", "device type"."slug", "device type"."name", "device type"."is of-cpu architecture", "device type"."logo", "device type"."contract", "device type"."belongs to-device family"
FROM "device type"
) AS "device.is of-device type"
WHERE "device"."is of-device type" = "device.is of-device type"."id"
) AS "device.is of-device type"
) AS "is_of__device_type", "device"."id"
FROM (
SELECT "device"."created at", "device"."modified at", "device"."id", "device"."actor", "device"."api heartbeat state", "device"."uuid", "device"."local id", "device"."device name", "device"."note", "device"."is of-device type", "device"."belongs to-application", "device"."is online", "device"."last connectivity event", "device"."is connected to vpn", "device"."last vpn event", "device"."is locked until-date", "device"."logs channel", "device"."public address", "device"."vpn address", "device"."ip address", "device"."mac address", "device"."memory usage", "device"."memory total", "device"."storage block device", "device"."storage usage", "device"."storage total", "device"."cpu usage", "device"."cpu temp", "device"."is undervolted", "device"."cpu id", "device"."is running-release", "device"."download progress", "device"."status", "device"."os version", "device"."os variant", "device"."supervisor version", "device"."provisioning progress", "device"."provisioning state", "device"."api port", "device"."api secret", "device"."is managed by-service instance", "device"."should be running-release", "device"."should be operated by-release", "device"."is managed by-device", "device"."should be managed by-release", 0 AS "is web accessible", CASE
WHEN ("device"."status" IN ('Ordered', 'Preparing')
OR "device"."is online" = 0
AND "device"."status" = 'Shipped') THEN LOWER("device"."status")
WHEN 1 = 0 THEN 'inactive'
WHEN "device"."provisioning state" = 'Post-Provisioning' THEN 'post-provisioning'
WHEN "device"."is online" = 0
AND "device"."api heartbeat state" IN ('offline', 'unknown')
AND "device"."last connectivity event" IS NULL THEN 'configuring'
WHEN "device"."is online" = 0
AND "device"."api heartbeat state" IN ('offline', 'unknown') THEN 'offline'
WHEN "device"."download progress" IS NOT NULL
AND "device"."status" = 'Downloading' THEN 'updating'
WHEN "device"."provisioning progress" IS NOT NULL THEN 'configuring'
WHEN EXISTS (
SELECT 1
FROM "image install"
WHERE "image install"."device" = "device"."id"
AND "image install"."download progress" IS NOT NULL
AND "image install"."status" = 'Downloading'
) THEN 'updating'
ELSE 'idle'
END AS "overall status", CASE
WHEN ("device"."status" IN ('Ordered', 'Preparing')
OR "device"."is online" = 0
AND "device"."status" = 'Shipped'
OR 1 = 0) THEN NULL
WHEN "device"."provisioning state" = 'Post-Provisioning' THEN "device"."provisioning progress"
WHEN "device"."is online" = 0
AND "device"."api heartbeat state" IN ('offline', 'unknown')
AND "device"."last connectivity event" IS NULL THEN "device"."provisioning progress"
WHEN "device"."is online" = 0
AND "device"."api heartbeat state" IN ('offline', 'unknown') THEN NULL
WHEN "device"."download progress" IS NOT NULL
AND "device"."status" = 'Downloading' THEN "device"."download progress"
WHEN "device"."provisioning progress" IS NOT NULL THEN "device"."provisioning progress"
WHEN EXISTS (
SELECT 1
FROM "image install"
WHERE "image install"."device" = "device"."id"
AND "image install"."download progress" IS NOT NULL
AND "image install"."status" = 'Downloading'
) THEN (
SELECT CAST(ROUND(AVG(COALESCE("image install"."download progress", 100))) AS INTEGER)
FROM "image install"
WHERE "image install"."device" = "device"."id"
AND "image install"."status" != 'deleted'
AND ("image install"."status" = 'Downloading'
OR "image install"."is provided by-release" = COALESCE("device"."should be running-release", (
SELECT "application"."should be running-release"
FROM "application"
WHERE "device"."belongs to-application" = "application"."id"
)))
)
ELSE NULL
END AS "overall progress"
FROM "device"
WHERE (("device"."actor") IS NOT NULL AND ("device"."actor") = ($1)
OR EXISTS (
SELECT 1
FROM "device" AS "device.is managed by-device"
WHERE "device"."is managed by-device" = "device.is managed by-device"."id"
AND (("device.is managed by-device"."actor") IS NOT NULL AND ("device.is managed by-device"."actor") = ($1)
OR EXISTS (
SELECT 1
FROM "device" AS "device.is managed by-device.is managed by-device"
WHERE "device.is managed by-device"."is managed by-device" = "device.is managed by-device.is managed by-device"."id"
AND 1 = 0
)
OR EXISTS (
SELECT 1
FROM "application" AS "device.is managed by-device.belongs to-application"
WHERE "device.is managed by-device"."belongs to-application" = "device.is managed by-device.belongs to-application"."id"
AND EXISTS (
SELECT 1
FROM "application" AS "dev.is managed by-dev.bel to-appl.depends on-application"
WHERE "device.is managed by-device.belongs to-application"."depends on-application" = "dev.is managed by-dev.bel to-appl.depends on-application"."id"
AND EXISTS (
SELECT 1
FROM "device" AS "dev.is managed by-dev.bel to-appl.depends on-appl.owns-device"
WHERE "dev.is managed by-dev.bel to-appl.depends on-application"."id" = "dev.is managed by-dev.bel to-appl.depends on-appl.owns-device"."belongs to-application"
AND ("dev.is managed by-dev.bel to-appl.depends on-appl.owns-device"."actor") IS NOT NULL AND ("dev.is managed by-dev.bel to-appl.depends on-appl.owns-device"."actor") = ($1)
)
)
))
)
OR EXISTS (
SELECT 1
FROM "application" AS "device.belongs to-application"
WHERE "device"."belongs to-application" = "device.belongs to-application"."id"
AND EXISTS (
SELECT 1
FROM "application" AS "device.belongs to-application.depends on-application"
WHERE "device.belongs to-application"."depends on-application" = "device.belongs to-application.depends on-application"."id"
AND EXISTS (
SELECT 1
FROM "device" AS "dev.belongs to-application.depends on-application.owns-device"
WHERE "device.belongs to-application.depends on-application"."id" = "dev.belongs to-application.depends on-application.owns-device"."belongs to-application"
AND ("dev.belongs to-application.depends on-application.owns-device"."actor") IS NOT NULL AND ("dev.belongs to-application.depends on-application.owns-device"."actor") = ($1)
)
)
))
) AS "device"
WHERE "device"."id" IN ($2)
AND "device"."supervisor version" IS NULL [ 122, 61 ]
Insert ID: image_install 5764704
Insert ID: image_install 5764705
Insert ID: image_install 5764706
Insert ID: image_install 5764707
Insert ID: image_install 5764708
DatabaseError: Rolling back transaction
at PostgresTx._rollback (/usr/src/app/node_modules/@_balena/pinejs/src/database-layer/db.ts:587:19)
at PostgresTx.rollback (/usr/src/app/node_modules/@_balena/pinejs/src/database-layer/db.ts:341:25)
at Object.transaction (/usr/src/app/node_modules/@_balena/pinejs/src/database-layer/db.ts:433:15)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async statePatchV2 (/usr/src/app/src/features/device-state/routes/state-patch-v2.ts:384:4)
[followed by 3 repetitions of the same DatabaseError stack message]
EDIT: followed immediately by a 401 error, even after setting the api secret
column:
2022-05-11T20:12:41.844Z 207.81.194.15 a/85 PATCH /device/v2/964534cf6773f131fa75a370fdc99495/state 401 29.531ms -