Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_destroy functions might need foreign import safe? #201

Closed
JackKelly-Bellroy opened this issue Dec 11, 2024 · 3 comments
Closed

_destroy functions might need foreign import safe? #201

JackKelly-Bellroy opened this issue Dec 11, 2024 · 3 comments

Comments

@JackKelly-Bellroy
Copy link

We recently had an alarm in one of our Kafka producers caused by an AWS Lambda Function apparently crashing with this message:

bootstrap: schedule: re-entered unsafely.
Perhaps a 'foreign import unsafe' should be 'safe'? 

(Context: We statically link Haskell binaries using hw-kafka-client and run them on AWS Lambda to produce Kafka records.)

This is the only place in hw-kafka-client where I can see foreign import unsafe:

foreign import ccall unsafe "rdkafka.h &rd_kafka_topic_partition_list_destroy"
rdKafkaTopicPartitionListDestroyF :: FinalizerPtr RdKafkaTopicPartitionListT
foreign import ccall unsafe "rdkafka.h rd_kafka_topic_partition_list_destroy"
rdKafkaTopicPartitionListDestroy :: Ptr RdKafkaTopicPartitionListT -> IO ()

Lambda periodically terminates and re-launches binaries, even if they're running well, to "keep the execution environments fresh". One possible hypothesis, though I don't know FFI-level stuff that well: is it possible for the binary to have been put to sleep by the Lambda service (which either suspends the microVM or stops the process, possibly both?) inside an FFI call, then a SIGTERM causes finalisers to begin running while still inside the FFI call?

Should these be made foreign import safe?

@AlexeyRaga
Copy link
Member

I had that one previously, but very rarely and I wasn't able to figure out where it came from.
I don't remember what I tried though. I believe that I did try making things safe/unsafe... Which ones - don't know :)

@lrworth
Copy link

lrworth commented Jan 16, 2025

As explained in #204, we removed all the unsafe markings and still saw that schedule: re-entered unsafely error; so this issue may be unrelated to hw-kafka-client.

@JackKelly-Bellroy
Copy link
Author

To be clear in case someone else finds this, we had forgotten to enable -threaded on certain binaries, and this seems to have made the problem go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants