Skip to content

Silent failure when parsing integer configuration values (MQTT/Kafka) #2962

@MOHITKOURAV01

Description

@MOHITKOURAV01

Bug Report: Silent Integer Parsing Failures in GoFr Container

Describe the bug

Several configuration values in pkg/gofr/container/container.go are parsed using strconv.Atoi where the returned error is explicitly ignored (assigned to _). If a user provides an invalid value (e.g., a non-numeric string or a value with units like "500ms"), the configuration silently defaults to 0 without any log or warning.

This affects:

  • MQTT_PORT (Line 182)
  • PARTITION_SIZE (Line 331)
  • PUBSUB_OFFSET (Line 339)
  • KAFKA_BATCH_SIZE (Line 340)
  • KAFKA_BATCH_BYTES (Line 341)
  • KAFKA_BATCH_TIMEOUT (Line 342)

For example, setting KAFKA_BATCH_TIMEOUT="500ms" results in a timeout of 0 (likely misinterpreted as 0ms or immediate timeout), whereas the intention was 500 milliseconds.

To Reproduce

Steps to reproduce the behavior:

  1. Set an invalid integer value for one of the affected configurations in your .env file or environment variables:

    export MQTT_PORT="invalid_port"
    export KAFKA_BATCH_TIMEOUT="500ms"```
    
    
  2. Initialize a GoFr application that uses these configurations (e.g., utilizing MQTT or Kafka PubSub).

  3. The application starts without any error logs, but the port will be set to 0 and the timeout to 0.

Expected behavior
The application should validate the integer configuration. If parsing fails, it should log a warning to inform the user that the provided value is invalid and state that it is falling back to the default value.

Screenshots
N/A

Environments (please complete the following information):

  • OS:OS: macOS
  • gofr version: development
  • go version: 1.25

More description
I have identified the issue in pkg/gofr/container/container.go and can implement a helper function getIntConfig that handles the strconv.Atoi error by logging a warning and returning the default value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageThe issue needs triaging.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions