{"id":26848301,"url":"https://github.com/canack/nats-header-problem","last_synced_at":"2025-03-30T20:54:01.456Z","repository":{"id":263942673,"uuid":"866751461","full_name":"canack/nats-header-problem","owner":"canack","description":"The example code that gives panic","archived":false,"fork":false,"pushed_at":"2024-10-02T20:10:06.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-21T05:37:09.153Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/canack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-02T20:05:48.000Z","updated_at":"2024-10-02T20:10:10.000Z","dependencies_parsed_at":"2024-11-21T05:37:13.226Z","dependency_job_id":"2ce27d0e-2239-4e05-8ea4-47f533f82750","html_url":"https://github.com/canack/nats-header-problem","commit_stats":null,"previous_names":["canack/nats-header-problem"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canack%2Fnats-header-problem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canack%2Fnats-header-problem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canack%2Fnats-header-problem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canack%2Fnats-header-problem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/canack","download_url":"https://codeload.github.com/canack/nats-header-problem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246379373,"owners_count":20767696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-30T20:54:00.957Z","updated_at":"2025-03-30T20:54:01.449Z","avatar_url":"https://github.com/canack.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NATS Go Client Header Bug Demonstration\n\nThis repository demonstrates a bug in the NATS Go client where setting headers on messages that initially lack them causes a panic.\n\n## Overview\n\nIn NATS, messages can have headers for storing metadata. The issue occurs when a consumer attempts to add or modify headers on a message that originally does not have any headers, leading to an application crash.\n\n## Problem Description\n\n### Steps to Reproduce\n\n1. **Producer**: Sends messages to a NATS subject.\n    - The first three messages include a \"Publish-Count\" header.\n    - Subsequent messages do not include any headers.\n\n2. **Consumer**: Receives messages and attempts to set a new header \"No-Panic\":\n    - If the message already has headers, the operation succeeds.\n    - If the message has no headers, the operation causes a panic due to the lack of header initialization.\n\n### Illustration\n\n```plaintext  \n  Scenario 1: Message with Initial Headers  \n  +-----------------+                       +--------------------+  \n  |  Producer       |    Send Message       |  Consumer          |  \n  |  (with headers) |----------------------\u003e|  Reads Headers     |  \n  +-----------------+                       |  Set/Add Header    |  \n                                            |  (success)         |  \n                                            +--------------------+  \n\n  Scenario 2: Message without Initial Headers  \n  +-----------------+                       +--------------------+  \n  |  Producer       |    Send Message       |  Consumer          |  \n  | (no headers)    |----------------------\u003e|  Attempt Set/Add   |  \n  +-----------------+                        |  Header (panic!)  |  \n                                            +--------------------+  \n```\n\n## Solution\n\nTo fix this issue, ensure that the consumer checks if the message contains headers before setting new ones. If not, initialize the header map to prevent a panic and maintain application stability.\n\n### The related PR : https://github.com/nats-io/nats.go/pull/1724","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanack%2Fnats-header-problem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcanack%2Fnats-header-problem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanack%2Fnats-header-problem/lists"}