Skip to content

Commit

Permalink
add a sanity check while getting key from contextmap
Browse files Browse the repository at this point in the history
  • Loading branch information
VedantMahabaleshwarkar committed Jul 3, 2023
1 parent fbc8b1b commit e8415b8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/com/ibm/watson/modelmesh/ModelMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -4430,7 +4430,16 @@ private Object invokeLocalModel(CacheEntry<?> ce, Method method, Object[] args)
ce.upgradePriority(now + 3600_000L, now + 7200_000L); // (2 hours in future)
}
Map<String, String> contextMap = ThreadContext.getCurrentContext();
String vModelId = contextMap.getOrDefault(VMODELID, "");
String vModelId = null;
// We might arrive here from a path where the original call was with a modelid.
// Hence, it is possible to arrive here with a null contextMap because the vModelId was never set
// To avoid catching a null pointer exception we just sanity check instead.
if (contextMap == null) {
vModelId = "";
} else {
vModelId = contextMap.get(VMODELID);
}

// The future-waiting timeouts should not be needed, request threads are interrupted when their
// timeouts/deadlines expire, and the model loading thread that it waits for has its own timeout.
// But we still set a large one as a safeguard (there can be pathalogical cases where model-loading
Expand Down

0 comments on commit e8415b8

Please sign in to comment.