Skip to content

Commit 95f5b38

Browse files
marc0oloclaude
andcommitted
fix(rust/face-recognition): fix SSL recursion, did mismatch, storage panic in setup_models
- upload-models-to-canister.sh: remove ssl.create_default_context override (caused infinite recursion); use SSL_CERT_FILE + REQUESTS_CA_BUNDLE env vars instead - backend.did: setup_models returns variant { Ok: null; Err: text } not () - lib.rs: guard setup_models() with metadata check so missing files return Err instead of trapping the canister via storage::bytes().unwrap() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 883bcfe commit 95f5b38

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

rust/face-recognition/backend/backend.did

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ service : {
4646
"clear_face_recognition_model_bytes": () -> ();
4747
"append_face_detection_model_bytes": (bytes: blob) -> ();
4848
"append_face_recognition_model_bytes": (bytes: blob) -> ();
49-
"setup_models": () -> ();
49+
"setup_models": () -> (variant { Ok: null; Err: text });
5050

5151
// These endpoints are used only for testing and benchmarking.
5252
"run_detection": () -> (Detection) query;

rust/face-recognition/backend/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ fn models_ready() -> bool {
130130
/// this function loads them into in-memory models.
131131
#[ic_cdk::update]
132132
fn setup_models() -> Result<(), String> {
133+
if std::fs::metadata(FACE_DETECTION_FILE).is_err()
134+
|| std::fs::metadata(FACE_RECOGNITION_FILE).is_err()
135+
{
136+
return Err(
137+
"Model files not found — upload them first using append_face_detection_model_bytes \
138+
and append_face_recognition_model_bytes"
139+
.to_string(),
140+
);
141+
}
133142
setup(
134143
storage::bytes(FACE_DETECTION_FILE),
135144
storage::bytes(FACE_RECOGNITION_FILE),

rust/face-recognition/upload-models-to-canister.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ if [ ! -f "face-recognition.onnx" ]; then
2525
echo "Face recognition model not found — generating with $PYTHON (this may take a few minutes)..."
2626
"$PYTHON" -m pip install --quiet --prefer-binary facenet-pytorch torch onnx certifi
2727
"$PYTHON" << 'PYEOF'
28-
import os, ssl, certifi
28+
import os, certifi
2929
# Python from python.org on macOS doesn't ship with root certificates;
30-
# point urllib at the certifi bundle so pretrained weights can be downloaded.
30+
# point urllib and requests at the certifi bundle so pretrained weights download.
3131
os.environ['SSL_CERT_FILE'] = certifi.where()
32-
ssl.create_default_context = lambda *a, **kw: ssl.create_default_context(cafile=certifi.where())
32+
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
3333
import torch
3434
import facenet_pytorch
3535
resnet = facenet_pytorch.InceptionResnetV1(pretrained='vggface2').eval()

0 commit comments

Comments
 (0)