Skip to content

Commit

Permalink
remove FailFast config
Browse files Browse the repository at this point in the history
The FAIL_FAST config, which makes the server crash when it encounters
and unknown food group, is not really useful.
  • Loading branch information
mk6i committed Oct 21, 2024
1 parent 8a43ff6 commit 1f0e0a1
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 22 deletions.
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Config struct {
ODirPort string `envconfig:"ODIR_PORT" required:"true" val:"5197" description:"The port that the ODir service binds to."`
DBPath string `envconfig:"DB_PATH" required:"true" val:"oscar.sqlite" description:"The path to the SQLite database file. The file and DB schema are auto-created if they doesn't exist."`
DisableAuth bool `envconfig:"DISABLE_AUTH" required:"true" val:"true" description:"Disable password check and auto-create new users at login time. Useful for quickly creating new accounts during development without having to register new users via the management API."`
FailFast bool `envconfig:"FAIL_FAST" required:"true" val:"false" description:"Crash the server in case it encounters a client message type it doesn't recognize. This makes failures obvious for debugging purposes."`
LogLevel string `envconfig:"LOG_LEVEL" required:"true" val:"info" description:"Set logging granularity. Possible values: 'trace', 'debug', 'info', 'warn', 'error'."`
OSCARHost string `envconfig:"OSCAR_HOST" required:"true" val:"127.0.0.1" description:"The hostname that AIM clients connect to in order to reach OSCAR services (auth, BOS, BUCP, etc). Make sure the hostname is reachable by all clients. For local development, the default loopback address should work provided the server and AIM client(s) are running on the same machine. For LAN-only clients, a private IP address (e.g. 192.168..) or hostname should suffice. For clients connecting over the Internet, specify your public IP address and ensure that TCP ports 5190-5197 are open on your firewall."`
}
Expand Down
1 change: 1 addition & 0 deletions config/ras.service
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Environment="DB_PATH=/var/ras/oscar.sqlite"
Environment="DISABLE_AUTH=true"
Environment="FAIL_FAST=false"
Environment="LOG_LEVEL=info"
Environment="ODIR_PORT=5197"
Environment="OSCAR_HOST=127.0.0.1"
ExecStart=/opt/ras/retro_aim_server
Restart=on-failure
Expand Down
4 changes: 0 additions & 4 deletions config/settings.env
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ export DB_PATH=oscar.sqlite
# new users via the management API.
export DISABLE_AUTH=true

# Crash the server in case it encounters a client message type it doesn't
# recognize. This makes failures obvious for debugging purposes.
export FAIL_FAST=false

# Set logging granularity. Possible values: 'trace', 'debug', 'info', 'warn',
# 'error'.
export LOG_LEVEL=info
Expand Down
7 changes: 2 additions & 5 deletions server/oscar/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ func (rt AdminServer) handleNewConnection(ctx context.Context, rwc io.ReadWriteC
return err
}

return dispatchIncomingMessagesSimple(ctx, sess, flapc, rwc, rt.Logger, rt.Handler, rt.Config)
return dispatchIncomingMessagesSimple(ctx, sess, flapc, rwc, rt.Logger, rt.Handler)
}

func dispatchIncomingMessagesSimple(ctx context.Context, sess *state.Session, flapc *wire.FlapClient, r io.Reader, logger *slog.Logger, router Handler, config config.Config) error {
func dispatchIncomingMessagesSimple(ctx context.Context, sess *state.Session, flapc *wire.FlapClient, r io.Reader, logger *slog.Logger, router Handler) error {
defer func() {
logger.InfoContext(ctx, "user disconnected")
}()
Expand Down Expand Up @@ -151,9 +151,6 @@ func dispatchIncomingMessagesSimple(ctx context.Context, sess *state.Session, fl
if err1 := sendInvalidSNACErr(inFrame, flapc); err1 != nil {
return errors.Join(err1, err)
}
if config.FailFast {
panic(err.Error())
}
break
}
return err
Expand Down
2 changes: 1 addition & 1 deletion server/oscar/bos.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ func (rt BOSServer) handleNewConnection(ctx context.Context, rwc io.ReadWriteClo
return err
}

return dispatchIncomingMessages(ctx, sess, flapc, rwc, rt.Logger, rt.Handler, rt.Config)
return dispatchIncomingMessages(ctx, sess, flapc, rwc, rt.Logger, rt.Handler)
}
2 changes: 1 addition & 1 deletion server/oscar/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ func (rt ChatServer) handleNewConnection(ctx context.Context, rwc io.ReadWriteCl
}

ctx = context.WithValue(ctx, "screenName", chatSess.IdentScreenName())
return dispatchIncomingMessages(ctx, chatSess, flapc, rwc, rt.Logger, rt.Handler, rt.Config)
return dispatchIncomingMessages(ctx, chatSess, flapc, rwc, rt.Logger, rt.Handler)
}
10 changes: 3 additions & 7 deletions server/oscar/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"log/slog"

"github.com/mk6i/retro-aim-server/config"
"github.com/mk6i/retro-aim-server/server/oscar/middleware"
"github.com/mk6i/retro-aim-server/state"
"github.com/mk6i/retro-aim-server/wire"
Expand All @@ -34,7 +33,7 @@ func sendInvalidSNACErr(frameIn wire.SNACFrame, rw ResponseWriter) error {
// or when the session closes.
//
// todo: this method has too many params and should be folded into a new type
func dispatchIncomingMessages(ctx context.Context, sess *state.Session, flapc *wire.FlapClient, r io.Reader, logger *slog.Logger, router Handler, config config.Config) error {
func dispatchIncomingMessages(ctx context.Context, sess *state.Session, flapc *wire.FlapClient, r io.Reader, logger *slog.Logger, router Handler) error {
defer func() {
logger.InfoContext(ctx, "user disconnected")
}()
Expand Down Expand Up @@ -80,9 +79,6 @@ func dispatchIncomingMessages(ctx context.Context, sess *state.Session, flapc *w
if err1 := sendInvalidSNACErr(inFrame, flapc); err1 != nil {
return errors.Join(err1, err)
}
if config.FailFast {
panic(err.Error())
}
break
}
return err
Expand All @@ -107,10 +103,10 @@ func dispatchIncomingMessages(ctx context.Context, sess *state.Session, flapc *w
}
middleware.LogRequest(ctx, logger, m.Frame, m.Body)
case <-sess.Closed():
// disconnect with error code that indicates user was kicked off by
// another sign on event
block := wire.TLVRestBlock{}
// error code indicating user signed in a different location
block.Append(wire.NewTLVBE(0x0009, uint8(0x01)))
// "more info" button
block.Append(wire.NewTLVBE(0x000b, "https://github.com/mk6i/retro-aim-server"))
if err := flapc.SendSignoffFrame(block); err != nil {
return fmt.Errorf("unable to gracefully disconnect user. %w", err)
Expand Down
5 changes: 2 additions & 3 deletions server/oscar/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/mk6i/retro-aim-server/config"
"github.com/mk6i/retro-aim-server/state"
"github.com/mk6i/retro-aim-server/wire"
)
Expand All @@ -26,7 +25,7 @@ func TestHandleChatConnection_MessageRelay(t *testing.T) {
clientReader, serverWriter := io.Pipe()
go func() {
flapc := wire.NewFlapClient(0, nil, serverWriter)
err := dispatchIncomingMessages(context.Background(), sess, flapc, serverReader, slog.Default(), nil, config.Config{})
err := dispatchIncomingMessages(context.Background(), sess, flapc, serverReader, slog.Default(), nil)
assert.NoError(t, err)
}()

Expand Down Expand Up @@ -145,7 +144,7 @@ func TestHandleChatConnection_ClientRequest(t *testing.T) {
clientReader, serverWriter := io.Pipe()
go func() {
flapc := wire.NewFlapClient(0, nil, serverWriter)
assert.NoError(t, dispatchIncomingMessages(context.Background(), sess, flapc, serverReader, slog.Default(), router, config.Config{}))
assert.NoError(t, dispatchIncomingMessages(context.Background(), sess, flapc, serverReader, slog.Default(), router))
}()

// send client messages
Expand Down

0 comments on commit 1f0e0a1

Please sign in to comment.