Skip to content

Commit 9b50138

Browse files
committed
[Carbonreceiver] Do not report fatal error when closed normally
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 941d873 commit 9b50138

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: carbonreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Do not report fatal error when closed normally
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [31913]
14+
15+
# If your change doesn't affect end users or the exported elements of any package,
16+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
17+
# Optional: The change log or logs in which this entry should be included.
18+
# e.g. '[user]' or '[user, api]'
19+
# Include 'user' if the change is relevant to end users.
20+
# Include 'api' if there is a change to a library API.
21+
# Default: '[user]'
22+
change_logs: [user]

receiver/carbonreceiver/internal/transport/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type Server interface {
2323
// ListenAndServe is a blocking call that starts to listen for client messages
2424
// on the specific transport, and prepares the message to be processed by
2525
// the Parser and passed to the next consumer.
26+
//
27+
// Returns net.ErrClosed when closed.
2628
ListenAndServe(
2729
p protocol.Parser,
2830
mc consumer.Metrics,

receiver/carbonreceiver/receiver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"errors"
99
"fmt"
10+
"net"
1011
"strings"
1112

1213
"go.opentelemetry.io/collector/component"
@@ -96,7 +97,7 @@ func (r *carbonReceiver) Start(_ context.Context, _ component.Host) error {
9697
}
9798
r.server = server
9899
go func() {
99-
if err := r.server.ListenAndServe(r.parser, r.nextConsumer, r.reporter); err != nil {
100+
if err := r.server.ListenAndServe(r.parser, r.nextConsumer, r.reporter); err != nil && !errors.Is(err, net.ErrClosed) {
100101
r.settings.ReportStatus(component.NewFatalErrorEvent(err))
101102
}
102103
}()

receiver/carbonreceiver/receiver_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
15+
"go.opentelemetry.io/collector/component"
1516
"go.opentelemetry.io/collector/component/componenttest"
1617
"go.opentelemetry.io/collector/config/confignet"
1718
"go.opentelemetry.io/collector/consumer"
@@ -192,6 +193,9 @@ func Test_carbonreceiver_EndToEnd(t *testing.T) {
192193
rt := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder))
193194
cs := receivertest.NewNopCreateSettings()
194195
cs.TracerProvider = rt
196+
cs.ReportStatus = func(event *component.StatusEvent) {
197+
assert.NoError(t, event.Err())
198+
}
195199
rcv, err := newMetricsReceiver(cs, *cfg, sink)
196200
require.NoError(t, err)
197201
r := rcv.(*carbonReceiver)

0 commit comments

Comments
 (0)