Closed OTP-Maintainer closed 3 years ago
vincefoley
said:
I was able to track it further down to opening a port.. this also fails the second match:
{code}
port_test() ->
seq_trace:set_token(label, 123),
?assertMatch({_, 123, _, _, _}, seq_trace:get_token()),
_Port = open_port({spawn, "echo hello"}, [stream]),
?assertMatch({_, 123, _, _, _}, seq_trace:get_token()).
{code}
lukas
said:
seq_trace tokens are not carried across ports, so this is behavior is intended.
http://erlang.org/doc/man/seq_trace.html#id149437
It would be nice to be able to do what you are describing, but it has not been implemented yet.
We are gradually moving more and more of the port functionality into NIFs which do not have this problem, so it may solve itself in the future.
vincefoley
said:
I saw that bit of the documentation, but my understanding was that the token doesn't work "across" ports, as in the token isn't sent to the port. It wasn't clear that the token will actually be lost when the port call returns.
The behavior renders seq_trace pretty un-predictable, because common operations like opening a file, etc cause the token to be dropped.
Do you think it would be a reasonable feature request to fix this? Perhaps the token could simply be saved before a port operation, and re-set after it?
lukas
said:
If you think about ports as processes, then what happens is that the message being sent to the port (using port_command for instance) has the seq_trace token, but the reply from the port does not, which means that the token is set cleared. So there should be someway for the port to attach the seq_trace token to the messages that it sets.
I've attempted to implement this and similar features in the past and they seem trivial at first but quickly become quite complicated.
I think that we would be open to patches that solve this issue, but as we are in general moving away from ports and into nifs, I don't believe that we will prioritize implementing this.
vincefoley
said:
OK, thanks for the feedback! I'll be looking forward to the nif based future!
vincefoley
said:
Hello there!
I was reading some erlang source, as one does, and came across this...
https://github.com/erlang/otp/blame/master/lib/kernel/test/seq_trace_SUITE.erl#L491
"OTP-4218 Messages from ports should not affect seq trace token"
Would this indicate that it's trying to ensure that the token isn't reset by the port message?
lukas
said:
hmm, yes you are correct. The problem isn't messages sent by ports as I originally though, but messages that erts generates in order to make asynchronous requests synchronous.
I'll have to think a bit about what the best approach to solve this is.
Thanks for sticking with this! Turns out that it was a larger problem than I tough as this does not only effect ports, but many other scenarios as well.
lukas
said:
A PR fixing this is now available: https://github.com/erlang/otp/pull/1846
vincefoley
said:
Awesome, thanks!
Original reporter:
vincefoley
Affected version:Not Specified
Fixed in version:OTP-21.1
Component:erts
Migrated from: https://bugs.erlang.org/browse/ERL-602