Closed bassosimone closed 4 years ago
It is confirmed that the following diff is enough to prevent the crash:
diff --git a/internal/oonitemplates/oonitemplates.go b/internal/oonitemplates/oonitemplates.go
index 80552c2..1701fce 100644
--- a/internal/oonitemplates/oonitemplates.go
+++ b/internal/oonitemplates/oonitemplates.go
@@ -17,7 +17,6 @@ import (
"net/http"
"net/url"
"sync"
- "sync/atomic"
"time"
goptlib "git.torproject.org/pluggable-transports/goptlib.git"
@@ -32,7 +31,6 @@ import (
type channelHandler struct {
ch chan<- modelx.Measurement
- lateWrites int64
}
func (h *channelHandler) OnMeasurement(m modelx.Measurement) {
@@ -44,7 +42,6 @@ func (h *channelHandler) OnMeasurement(m modelx.Measurement) {
select {
case h.ch <- m:
case <-time.After(100 * time.Millisecond):
- atomic.AddInt64(&h.lateWrites, 1)
}
}
diff --git a/internal/oonitemplates/oonitemplates_test.go b/internal/oonitemplates/oonitemplates_test.go
index 797696d..9311cff 100644
--- a/internal/oonitemplates/oonitemplates_test.go
+++ b/internal/oonitemplates/oonitemplates_test.go
@@ -5,33 +5,14 @@ import (
"errors"
"net"
"strings"
- "sync"
"testing"
"time"
goptlib "git.torproject.org/pluggable-transports/goptlib.git"
- "github.com/ooni/netx/modelx"
"gitlab.com/yawning/obfs4.git/transports"
obfs4base "gitlab.com/yawning/obfs4.git/transports/base"
)
-func TestUnitChannelHandlerWriteLateOnChannel(t *testing.T) {
- handler := &channelHandler{
- ch: make(chan modelx.Measurement),
- }
- var waitgroup sync.WaitGroup
- waitgroup.Add(1)
- go func() {
- time.Sleep(1 * time.Second)
- handler.OnMeasurement(modelx.Measurement{})
- waitgroup.Done()
- }()
- waitgroup.Wait()
- if handler.lateWrites != 1 {
- t.Fatal("unexpected lateWrites value")
- }
-}
-
func TestIntegrationDNSLookupGood(t *testing.T) {
ctx := context.Background()
results := DNSLookup(ctx, DNSLookupConfig{
Now the question is why this happens.
This issue has been very useful to teach me facts about github.com/ooni/probe-engine. I have mentioned some of the issues that it inspired above and I am going to mention more issues below.
This should now be fixed by https://github.com/ooni/probe-engine/pull/360. This was of course priority/high because it was blocking me from finalising https://github.com/measurement-kit/measurement-kit/issues/1913. This has been effort/L for me, since, in one way or another, it blocked me for ~2 days. But it was also a learning moment and prompted a bunch of follow up issues.
It seems my overall knowledge is such that I cannot determine why the code was wrong at present, which suggests that (1) probably code should be simpler and (2) I may be in the future. Since I have been blocked on this issue for quite some time now, I feel okay to commit the workaround in https://github.com/ooni/probe-engine/pull/360 to master and finish with experimenting with the ooni/probe-android app to see how to sketch out integrating it with Go code.
For completeness, this was actually https://github.com/ooni/probe-engine/issues/399.
Just seen this crash on Android x86:
Of course, this is part of https://github.com/measurement-kit/measurement-kit/issues/1913.
Note that I can't reproduce the crash with
android/x86_64
. Yet, onandroid/arm64
: