Commit ee74bbed218e6a106f672c6804b1dc65e4f51ffc
Committed by
Andrew Shvayka
1 parent
bfb055cc
fixed race condition during unreq and updating lwm2m client
Showing
3 changed files
with
17 additions
and
5 deletions
@@ -166,7 +166,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { | @@ -166,7 +166,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { | ||
166 | this.lwM2mClientsByRegistrationId.put(registration.getId(), client); | 166 | this.lwM2mClientsByRegistrationId.put(registration.getId(), client); |
167 | client.setState(LwM2MClientState.REGISTERED); | 167 | client.setState(LwM2MClientState.REGISTERED); |
168 | onUplink(client); | 168 | onUplink(client); |
169 | - if(!compareAndSetSleepFlag(client, false)){ | 169 | + if (!compareAndSetSleepFlag(client, false)) { |
170 | clientStore.put(client); | 170 | clientStore.put(client); |
171 | } | 171 | } |
172 | } finally { | 172 | } finally { |
@@ -316,7 +316,11 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { | @@ -316,7 +316,11 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { | ||
316 | public void update(LwM2mClient client) { | 316 | public void update(LwM2mClient client) { |
317 | client.lock(); | 317 | client.lock(); |
318 | try { | 318 | try { |
319 | - clientStore.put(client); | 319 | + if (client.getState().equals(LwM2MClientState.REGISTERED)) { |
320 | + clientStore.put(client); | ||
321 | + } else { | ||
322 | + log.error("[{}] Client is in invalid state: {}!", client.getEndpoint(), client.getState()); | ||
323 | + } | ||
320 | } finally { | 324 | } finally { |
321 | client.unlock(); | 325 | client.unlock(); |
322 | } | 326 | } |
@@ -106,6 +106,7 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> { | @@ -106,6 +106,7 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> { | ||
106 | 106 | ||
107 | public abstract OtaPackageType getType(); | 107 | public abstract OtaPackageType getType(); |
108 | 108 | ||
109 | + @JsonIgnore | ||
109 | public String getTargetPackageId() { | 110 | public String getTargetPackageId() { |
110 | return getPackageId(targetName, targetVersion); | 111 | return getPackageId(targetName, targetVersion); |
111 | } | 112 | } |
@@ -15,11 +15,13 @@ | @@ -15,11 +15,13 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.transport.lwm2m.server.store; | 16 | package org.thingsboard.server.transport.lwm2m.server.store; |
17 | 17 | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
18 | import org.nustaq.serialization.FSTConfiguration; | 19 | import org.nustaq.serialization.FSTConfiguration; |
19 | import org.springframework.data.redis.connection.RedisClusterConnection; | 20 | import org.springframework.data.redis.connection.RedisClusterConnection; |
20 | import org.springframework.data.redis.connection.RedisConnectionFactory; | 21 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
21 | import org.springframework.data.redis.core.Cursor; | 22 | import org.springframework.data.redis.core.Cursor; |
22 | import org.springframework.data.redis.core.ScanOptions; | 23 | import org.springframework.data.redis.core.ScanOptions; |
24 | +import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientState; | ||
23 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; | 25 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; |
24 | 26 | ||
25 | import java.util.ArrayList; | 27 | import java.util.ArrayList; |
@@ -27,6 +29,7 @@ import java.util.HashSet; | @@ -27,6 +29,7 @@ import java.util.HashSet; | ||
27 | import java.util.List; | 29 | import java.util.List; |
28 | import java.util.Set; | 30 | import java.util.Set; |
29 | 31 | ||
32 | +@Slf4j | ||
30 | public class TbRedisLwM2MClientStore implements TbLwM2MClientStore { | 33 | public class TbRedisLwM2MClientStore implements TbLwM2MClientStore { |
31 | 34 | ||
32 | private static final String CLIENT_EP = "CLIENT#EP#"; | 35 | private static final String CLIENT_EP = "CLIENT#EP#"; |
@@ -76,9 +79,13 @@ public class TbRedisLwM2MClientStore implements TbLwM2MClientStore { | @@ -76,9 +79,13 @@ public class TbRedisLwM2MClientStore implements TbLwM2MClientStore { | ||
76 | 79 | ||
77 | @Override | 80 | @Override |
78 | public void put(LwM2mClient client) { | 81 | public void put(LwM2mClient client) { |
79 | - byte[] clientSerialized = serializer.asByteArray(client); | ||
80 | - try (var connection = connectionFactory.getConnection()) { | ||
81 | - connection.getSet(getKey(client.getEndpoint()), clientSerialized); | 82 | + if (client.getState().equals(LwM2MClientState.UNREGISTERED)) { |
83 | + log.error("[{}] Client is in invalid state: {}!", client.getEndpoint(), client.getState(), new Exception()); | ||
84 | + } else { | ||
85 | + byte[] clientSerialized = serializer.asByteArray(client); | ||
86 | + try (var connection = connectionFactory.getConnection()) { | ||
87 | + connection.getSet(getKey(client.getEndpoint()), clientSerialized); | ||
88 | + } | ||
82 | } | 89 | } |
83 | } | 90 | } |
84 | 91 |