Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

Repository files navigation

APISIX Etcd Hanging Bug Reproduction

Docker APISIX etcd

A minimal reproduction setup for the APISIX etcd hanging issue where the API gateway hangs during initialization on the init_etcd phase, preventing proper route synchronization.

πŸ› Bug Description

Primary Root Cause:

Hardcoded default configuration overrides custom configuration files.

APISIX ignores custom config.yaml files and uses a hardcoded default http://127.0.0.1:2379 instead of the configured etcd service host.

Technical Details:

  • File: /usr/local/apisix/apisix/cli/config.lua (inside Docker image)
  • Problem: Hardcoded host = { "http://127.0.0.1:2379" } in the APISIX Docker image
  • Impact: Custom config with http://etcd:2379 gets ignored completely
  • Result: APISIX tries to connect to localhost instead of etcd service
  • Cascading Effect: This causes BOTH hanging AND addon syncing failures

Secondary Issue Discovered:

Process cleanup failure in test scripts causing intermittent failures.

During comprehensive testing, we discovered that improper process cleanup between test iterations caused nginx processes to accumulate, leading to port conflicts and configuration issues on subsequent iterations.

Technical Details of Secondary Issue:

  • Problem: Test scripts using kill $APISIX_PID instead of proper APISIX stop command
  • Impact: nginx master and worker processes remain running between iterations
  • Result: Port conflicts and configuration conflicts on 3rd+ iterations
  • Fix: Use /usr/bin/apisix stop for proper cleanup

Issue: APISIX hangs during initialization on the init_etcd phase, preventing:

  • Route synchronization with etcd
  • Admin API functionality
  • Proper system initialization
  • Route accessibility via HTTP
  • Addon/Plugin synchronization with etcd (cascading failure)

πŸ”— How Hardcoded Config Causes Cascading Failures:

  1. Primary Failure: APISIX uses hardcoded 127.0.0.1:2379 instead of etcd:2379
  2. Connection Failure: Cannot connect to localhost:2379 in container environment
  3. Initialization Hanging: APISIX hangs on init_etcd phase indefinitely
  4. Cascading Effects:
    • ❌ Admin API never becomes accessible
    • ❌ Plugin syncer cannot initialize (depends on etcd connection)
    • ❌ Addon/plugin configuration sync fails
    • ❌ Route management fails
    • ❌ All etcd-dependent functionality breaks

Symptoms:

  • APISIX process starts but never completes initialization
  • Logs show: Warning! Request etcd endpoint 'http://127.0.0.1:2379/version' error, connection refused
  • Admin API is not accessible
  • Routes created via Admin API return 404 when accessed via HTTP
  • Plugin/Addon configuration sync fails (direct result of hardcoded config)
  • Plugin configuration API endpoints are not accessible (direct result of hardcoded config)
  • etcd is healthy and accessible, but APISIX cannot sync with it due to wrong host

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • Git
  • Note: All commands require sudo privileges to access Docker daemon

1. Clone the Repository

git clone https://github.com/joggerjoel/apisix-etcd-hanging-bug.git
cd apisix-etcd-hanging-bug

2. Install Docker (if needed)

# If Docker is not installed, run the installation script
./install_docker.sh

# After installation, log out and log back in for group changes to take effect

3. Run the Bug Reproduction

# Easy way: Use the run script (requires sudo)
sudo ./run_bug.sh up

# For faster restarts (no rebuild): Use the restart script
sudo ./restart_bug.sh restart

# Or manually with docker-compose
sudo docker-compose -f docker-compose.bug.yml up --build

4. Test the Hanging Behavior

# Quick test (15 seconds)
sudo ./run_bug.sh test

# Full demonstration (30 seconds)
sudo ./run_bug.sh demo

# Test addon sync hanging behavior
sudo ./run_bug.sh addon-sync

# Test Admin API accessibility
sudo ./run_bug.sh admin-api

# Run comprehensive test (3 iterations) - NEW!
sudo ./run_bug.sh test-all

# Start APISIX to demonstrate hanging
sudo ./run_bug.sh start

# Investigate the configuration issue
sudo ./run_bug.sh investigate

# Fix the etcd configuration issue
sudo ./run_bug.sh fix

# Compare working vs hanging scenarios
sudo ./run_bug.sh compare

# View logs to see the hanging
sudo ./run_bug.sh logs

# Access container for manual investigation
sudo ./run_bug.sh shell

πŸ“ Repository Structure

apisix-etcd-hanging-bug/
β”œβ”€β”€ README.md                           # This file
β”œβ”€β”€ Dockerfile.bug                      # Minimal Dockerfile reproducing the issue
β”œβ”€β”€ docker-compose.bug.yml              # Docker Compose setup
β”œβ”€β”€ config.yaml                         # APISIX configuration
β”œβ”€β”€ .env                               # Centralized environment configuration
β”œβ”€β”€ run_bug.sh                          # Main script to run the bug reproduction
β”œβ”€β”€ restart_bug.sh                      # Lightweight restart script (no rebuild)
β”œβ”€β”€ common_functions.sh                 # Shared functions between scripts
β”œβ”€β”€ install_docker.sh                   # Docker installation script
β”œβ”€β”€ show_hanging.sh                     # Simple demonstration script
β”œβ”€β”€ test_addon_sync.sh                  # Addon sync hanging test
β”œβ”€β”€ test_admin_api.sh                   # Admin API accessibility test
β”œβ”€β”€ start_apisix.sh                     # Start APISIX to demonstrate hanging
β”œβ”€β”€ fix_admin_access.sh                 # Fix admin access restrictions
β”œβ”€β”€ comprehensive_test.sh               # Comprehensive test script (3 iterations)
β”œβ”€β”€ api_key.conf                        # API key configuration
β”œβ”€β”€ update_api_key.sh                   # Script to update API key in .env
└── .gitignore                          # Git ignore file

πŸ”§ Environment Configuration

All environment variables are centralized in .env:

# APISIX API Key - The key that APISIX generates and uses
APISIX_ADMIN_KEY=yDqxrnguAUwpHyHhgdRgRDWOPYJSHDnR

# APISIX Configuration
APISIX_ADMIN_URL=http://localhost:9180/apisix/admin
APISIX_ADMIN_PORT=9180
APISIX_GATEWAY_PORT=8080

# etcd Configuration
ETCD_HOST=etcd
ETCD_PORT=2379
ETCD_URL=http://etcd:2379

# Docker Configuration
DOCKER_COMPOSE_FILE=docker-compose.bug.yml
PROJECT_NAME=apisix-etcd-hanging-bug
APISIX_SERVICE=apisix-bug

# Test Configuration
TEST_ITERATIONS=3

This ensures consistency across all scripts and configurations. The API key is automatically passed to APISIX via environment variables.

Note: The .env file follows the standard convention for environment configuration files and is automatically ignored by git to prevent accidentally committing sensitive information.

πŸ”„ API Key Persistence

The .env file is mounted as a volume in the Docker container to ensure the API key persists across rebuilds:

volumes:
  - ./.env:/usr/local/apisix/.env:ro

When APISIX generates a new API key (which happens on each rebuild), you can update the .env file using:

sudo ./run_bug.sh update-key

This command will:

  1. Start APISIX and detect the current API key
  2. Update the .env file with the correct key
  3. Update all configuration files (config.yaml, Dockerfile, docker-compose.yml, README.md)
  4. Ensure consistency across all components

πŸ” What You'll See

When you run the reproduction setup, you should observe:

  1. βœ… etcd starts successfully and becomes healthy
  2. ❌ APISIX starts but hangs during initialization
  3. ❌ Demonstration script shows:
    • APISIX process is running but not responding
    • Logs show hanging on init_etcd phase
    • etcd is reachable but APISIX cannot sync
    • Admin API is not accessible
    • Route synchronization fails
    • Plugin/Addon configuration sync fails
    • Plugin configuration API endpoints are not accessible

πŸ›  Using the Scripts

Two Scripts Available:

  1. run_bug.sh - Full-featured script with build capabilities
  2. restart_bug.sh - Lightweight restart script (faster, no rebuild)

When to Use Which Script:

  • Use run_bug.sh for:

    • Initial setup and building
    • When you need to rebuild images
    • Full feature set including investigation tools
    • Development and debugging
  • Use restart_bug.sh for:

    • Quick restarts (much faster)
    • Testing and validation
    • When images are already built
    • Daily development workflow

run_bug.sh - Full-Featured Script

The run_bug.sh script provides convenient commands for managing the bug reproduction:

# Show all available commands
sudo ./run_bug.sh help

# Build and start services
sudo ./run_bug.sh up

# Stop services
sudo ./run_bug.sh down

# View logs from all services
sudo ./run_bug.sh logs

# View only APISIX logs
sudo ./run_bug.sh logs-apisix

# View only etcd logs
sudo ./run_bug.sh logs-etcd

# Run quick hanging test (15 seconds)
sudo ./run_bug.sh test

# Run full hanging demonstration (30 seconds)
sudo ./run_bug.sh demo

# Test addon sync hanging behavior
sudo ./run_bug.sh addon-sync

# Run comprehensive test (3 iterations) - NEW!
sudo ./run_bug.sh test-all

# Access APISIX container shell
sudo ./run_bug.sh shell

# Show service status and health checks
sudo ./run_bug.sh status

# Clean up everything (containers, images, volumes)
sudo ./run_bug.sh clean

restart_bug.sh - Lightweight Restart Script

The restart_bug.sh script provides fast restart capabilities without rebuilding:

# Show all available commands
sudo ./restart_bug.sh help

# Restart services (default command)
sudo ./restart_bug.sh
sudo ./restart_bug.sh restart

# Start services
sudo ./restart_bug.sh up

# Stop services
sudo ./restart_bug.sh down

# View logs from all services
sudo ./restart_bug.sh logs

# View only APISIX logs
sudo ./restart_bug.sh logs-apisix

# View only etcd logs
sudo ./restart_bug.sh logs-etcd

# Access APISIX container shell
sudo ./restart_bug.sh shell

# Run quick hanging test (15 seconds)
sudo ./restart_bug.sh test

# Run comprehensive test (3 iterations)
sudo ./restart_bug.sh test-all

# Test addon sync hanging behavior
sudo ./restart_bug.sh addon-sync

# Test Admin API accessibility
sudo ./restart_bug.sh admin-api

# Start APISIX to demonstrate hanging
sudo ./restart_bug.sh start

# Fix admin access configuration
sudo ./restart_bug.sh fix-admin

# Update API key in .env file
sudo ./restart_bug.sh update-key

# Show status of services
sudo ./restart_bug.sh status

# Clean up everything (containers, images, volumes)
sudo ./restart_bug.sh clean

Performance Comparison:

Operation run_bug.sh restart_bug.sh Speed Improvement
Restart ~30-60s (rebuild) ~5-10s (no rebuild) 6x faster
Test Same Same Same
Logs Same Same Same
Shell Same Same Same

πŸ§ͺ Comprehensive Testing

New: Comprehensive Test Suite

The reproduction now includes a comprehensive test suite that runs 3 iterations to verify that all fixes work consistently:

# Run comprehensive test (3 iterations)
sudo ./run_bug.sh test-all

What the comprehensive test does:

  1. Iteration 1: Tests all functionality (API key, route creation, plugin sync, etcd persistence)
  2. Iteration 2: Repeats all tests to verify consistency
  3. Iteration 3: Final verification that everything works reliably

Test Coverage:

  • βœ… API Key Authentication: Verifies Admin API accessibility
  • βœ… Plugin Configuration API: Tests plugin management endpoints
  • βœ… Route Creation: Creates test routes via Admin API
  • βœ… etcd Persistence: Verifies routes are stored in etcd
  • βœ… Plugin Sync: Tests addon/plugin configuration synchronization
  • βœ… Data Cleanup: Ensures test data is properly cleaned up
  • βœ… Process Management: Verifies proper APISIX startup/shutdown

Expected Results:

πŸŽ‰ ALL TESTS PASSED! (3/3)
βœ… etcd sync and addon plugin functionality is working consistently
βœ… APISIX configuration is stable and reliable
βœ… All fixes are working correctly

Process Cleanup Issue Discovery

During comprehensive testing, we discovered a secondary issue that caused intermittent failures:

Problem: Test scripts were using kill $APISIX_PID instead of the proper APISIX stop command, leaving nginx processes running between iterations.

Symptoms:

  • Tests 1 & 2 would pass
  • Test 3 would fail with HTTP 401 (wrong API key)
  • nginx processes accumulating between iterations
  • Port conflicts on subsequent iterations

Solution: Updated comprehensive test script to use /usr/bin/apisix stop for proper cleanup.

Impact: This discovery ensures the test suite is reliable and demonstrates that all fixes work consistently across multiple iterations.

πŸ” Manual Investigation

If you want to investigate further:

# Access the running container
sudo ./run_bug.sh shell

# Or manually with docker-compose
sudo docker exec -it apisix-etcd-hanging-bug_apisix-bug_1 bash

# Check APISIX logs
tail -f /tmp/apisix.log

# Check if APISIX process is running
ps aux | grep apisix

# Test etcd connectivity
nc -z etcd 2379

# Try to access Admin API (should fail)
curl -v http://localhost:9180/apisix/admin/services \
  -H "X-API-KEY: a663d5f8d98fd490408ad230fae57312"

# Try to access APISIX HTTP endpoint (should fail)
curl -v http://localhost:8080/

πŸ”§ Configuration Details

The minimal configuration that reproduces the bug:

deployment:
  role: traditional
  admin:
    admin_key:
      - name: admin
        key: ${APISIX_ADMIN_KEY}
        role: admin

apisix:
  node_listen: 80
  enable_admin: true
  admin_listen:
    ip: 0.0.0.0
    port: 9180
  allow_admin:
    - 0.0.0.0/0
  etcd:
    host:
      - "http://etcd:2379"
    prefix: "/apisix"
    timeout: 30

# Minimal plugin configuration
plugins:
  - serverless-pre-function

🎯 Expected vs Actual Behavior

Expected Behavior (Working System)

  • APISIX completes initialization in ~5-10 seconds
  • Admin API responds to requests
  • Routes can be created and accessed via HTTP
  • etcd synchronization works properly

Actual Behavior (Bug)

  • APISIX hangs on init_etcd phase indefinitely
  • Admin API is not accessible
  • Routes cannot be synchronized with etcd
  • HTTP requests to routes return 404
  • Plugin/Addon configurations cannot be synchronized with etcd
  • Plugin configuration API endpoints return errors

πŸ› Bug Characteristics

This bug has been observed with:

  • APISIX versions: 3.13.0, 3.12.0, 3.9.1 (not version-specific)
  • etcd versions: bitnami/etcd:latest, bitnami/etcd:3.4.15
  • Configuration types: Both minimal and complex configurations
  • Environment: Docker containers with proper networking

πŸ” Root Cause Analysis

Based on investigation, the issue appears to be:

  1. Not version-specific - occurs across multiple APISIX versions
  2. Not configuration-specific - occurs with minimal configs
  3. Not etcd-specific - etcd is healthy and accessible
  4. Environment-related - likely Docker environment or system configuration issue

🚨 What's Actually Breaking

The hanging issue is caused by hardcoded default configuration in the APISIX Docker image that overrides custom configuration files:

Primary Issue: Hardcoded etcd Host in Docker Image

  • File: /usr/local/apisix/apisix/cli/config.lua (inside Docker image)
  • Problem: Contains hardcoded host = { "http://127.0.0.1:2379" } in the APISIX Docker image
  • Impact: APISIX tries to connect to localhost instead of the etcd service
  • Result: Connection fails, causing hanging during initialization
  • Cascading Effect: This single hardcoded value breaks ALL etcd-dependent functionality

πŸ” Root Cause Investigation Results

The investigation script (sudo ./run_bug.sh investigate) reveals:

  1. βœ… Custom config file exists with correct etcd host: http://etcd:2379
  2. βœ… etcd service is reachable and responding correctly
  3. ❌ Hardcoded default overrides custom config: http://127.0.0.1:2379
  4. ❌ APISIX ignores custom config.yaml and uses hardcoded values
  5. ❌ localhost:2379 is not reachable (as expected in container environment)

Evidence from logs:

Use customized yaml: /usr/local/apisix/conf/config.yaml
Warning! Request etcd endpoint 'http://127.0.0.1:2379/version' error, connection refused
all etcd nodes are unavailable

This proves that APISIX loads the custom config file but still uses the hardcoded default!

Secondary Issue: Plugin Sync Failure (Cascading from Primary Issue)

  • Function: init_plugins_syncer() in /usr/local/apisix/apisix/plugin.lua
  • Problem: Tries to create etcd instance for fetching /plugins configuration
  • Root Cause: Cannot connect to etcd due to hardcoded 127.0.0.1:2379 configuration
  • Impact: Plugin/addon configuration sync fails
  • Result: Plugin configuration API endpoints become inaccessible
  • Note: This is NOT a separate issue - it's a direct result of the hardcoded etcd configuration

πŸ”§ Step-by-Step Breakdown for Contributors

Step 1: Environment Setup

# Clone and start the reproduction environment
git clone https://github.com/joggerjoel/apisix-etcd-hanging-bug.git
cd apisix-etcd-hanging-bug
sudo ./run_bug.sh up

What happens:

  • etcd starts successfully on etcd:2379
  • APISIX container builds with custom config pointing to http://etcd:2379
  • Both services are healthy and reachable

Step 2: Test General Hanging

sudo ./run_bug.sh test

What breaks:

  • APISIX starts but hangs during init_etcd phase
  • Logs show: request etcd endpoint 'http://127.0.0.1:2379/version' error, connection refused
  • APISIX never completes initialization
  • Admin API remains inaccessible

Step 3: Test Addon Sync Hanging

sudo ./run_bug.sh addon-sync

What breaks:

  • Plugin configuration sync fails
  • init_plugins_syncer() cannot create etcd instance for /plugins
  • Plugin configuration API endpoints return errors
  • Addon/plugin management becomes impossible

Step 4: Investigate the Root Cause

sudo ./run_bug.sh shell
# Inside container:
grep -A 5 -B 5 '127.0.0.1.*2379' /usr/local/apisix/apisix/cli/config.lua

What you'll find:

etcd = {
  host = { "http://127.0.0.1:2379" },  # ← This is the problem!
  prefix = "/apisix",
  timeout = 30,
  # ...
}

🎯 Expected vs Actual Behavior

Expected (Working System):

  1. APISIX reads custom config file (/usr/local/apisix/conf/config.yaml)
  2. Connects to etcd at http://etcd:2379
  3. Completes initialization in ~5-10 seconds
  4. Admin API responds to requests
  5. Plugin configuration sync works
  6. Routes can be created and accessed

Actual (Broken System):

  1. APISIX ignores custom config file
  2. Uses hardcoded default: http://127.0.0.1:2379
  3. Hangs indefinitely trying to connect to localhost
  4. Admin API never becomes accessible
  5. Plugin configuration sync fails
  6. Routes cannot be created or accessed

πŸ” Debugging Steps for Contributors

1. Verify etcd Connectivity

sudo ./run_bug.sh shell
# Inside container:
nc -z etcd 2379  # Should succeed
curl http://etcd:2379/version  # Should return etcd version

2. Check APISIX Configuration

# Inside container:
cat /usr/local/apisix/conf/config.yaml  # Shows correct config
grep -A 10 'etcd.*host' /usr/local/apisix/apisix/cli/config.lua  # Shows hardcoded default

3. Monitor APISIX Startup

# Inside container:
/usr/bin/apisix start -c /usr/local/apisix/conf/config.yaml 2>&1 | head -20

Expected output:

Use customized yaml: /usr/local/apisix/conf/config.yaml
Warning! Request etcd endpoint 'http://127.0.0.1:2379/version' error, connection refused

4. Test Plugin Sync

# Inside container:
grep -A 15 'init_plugins_syncer' /usr/local/apisix/apisix/plugin.lua

What you'll see:

function init_plugins_syncer()
    local err
    plugins_conf, err = core.config.new("/plugins", {
        automatic = true,
        item_schema = core.schema.plugins,
        # This fails because etcd connection is broken
    })
end

πŸ›  Solution: Fix etcd Configuration

The reproduction includes a fix that is automatically applied during the Docker build:

Automatic Fix Applied

The Dockerfile automatically fixes the hardcoded default during build:

# Fix the hardcoded etcd default to use etcd service instead of localhost
RUN sed -i 's|"http://127.0.0.1:2379"|"http://etcd:2379"|g' /usr/local/apisix/apisix/cli/config.lua

What the fix does:

  1. Modifies hardcoded config: Changes 127.0.0.1:2379 to etcd:2379 during build
  2. APISIX starts correctly: Connects to etcd service instead of localhost
  3. Admin API works: Becomes accessible after APISIX completes initialization
  4. No more hanging: APISIX completes startup successfully

Fix Methods Demonstrated

Method 1: Environment Variable Override

export APISIX_ETCD_HOST="http://etcd:2379"

Method 2: Configuration File Override

# Modify the hardcoded config file
sed -i 's|"http://127.0.0.1:2379"|"http://etcd:2379"|g' /usr/local/apisix/apisix/cli/config.lua

Method 3: Restore Original Config

# To restore the original configuration
cp /usr/local/apisix/apisix/cli/config.lua.backup /usr/local/apisix/apisix/cli/config.lua

Expected Results After Fix

  • βœ… APISIX connects to etcd service instead of localhost
  • βœ… APISIX completes initialization without hanging
  • βœ… Admin API becomes accessible (proper API responses)
  • βœ… Plugin Config API becomes accessible (proper API responses)
  • βœ… Addon synchronization works correctly
  • βœ… No more hanging behavior - APISIX starts successfully
  • βœ… Comprehensive testing passes - All 3 iterations work consistently
  • βœ… Process cleanup works properly - No nginx process accumulation

πŸ“Š Impact Assessment

Component Status Impact
etcd Service βœ… Healthy No issues
APISIX Container ❌ Hanging Cannot complete initialization
Admin API ❌ Inaccessible Cannot manage routes/services
Plugin Config API ❌ Inaccessible Cannot manage plugins/addons
Route Management ❌ Failed Cannot create or access routes
Plugin Sync ❌ Failed Cannot sync plugin configurations

🎯 Key Takeaways for Contributors

  1. The bug is reproducible - The script consistently demonstrates the hanging behavior
  2. Root cause is identified - Hardcoded default configuration overrides custom config
  3. Multiple components affected - Both general initialization and plugin sync fail
  4. Environment-specific - Works in some environments, fails in others
  5. Fix requires configuration override - Need to ensure custom config takes precedence

πŸ“‘ Admin API Testing

The reproduction includes comprehensive Admin API testing to demonstrate when it works vs when it hangs:

Test Admin API Accessibility

sudo ./run_bug.sh admin-api

What this shows:

  • βœ… etcd is healthy and accessible
  • ❌ Admin API is not accessible (HTTP 000 - connection refused)
  • ❌ Plugin Config API is not accessible
  • 🚨 APISIX is running but Admin API is not accessible (hanging issue)

Compare Working vs Hanging Scenarios

sudo ./run_bug.sh compare

What this demonstrates:

  1. Scenario 1: APISIX not running (current state)

    • etcd is healthy
    • Admin API not accessible (expected)
  2. Scenario 2: APISIX running but hanging (bug reproduction)

    • etcd is healthy
    • APISIX starts but hangs during initialization
    • Admin API not accessible (due to hanging)
  3. Scenario 3: APISIX working correctly (theoretical)

    • etcd is healthy
    • APISIX completes initialization
    • Admin API accessible (HTTP 200)
    • Plugin Config API accessible (HTTP 200)

Expected vs Actual Admin API Behavior

Scenario etcd Status APISIX Status Admin API Plugin Config API
Working βœ… Healthy βœ… Running βœ… HTTP 200 βœ… HTTP 200
Hanging βœ… Healthy ❌ Hanging ❌ HTTP 000 ❌ HTTP 000
Not Running βœ… Healthy ❌ Not Started ❌ HTTP 000 ❌ HTTP 000

Admin API Test Commands

# Test Admin API when APISIX is working (should return HTTP 200)
curl http://localhost:9180/apisix/admin/services \
  -H "X-API-KEY: a663d5f8d98fd490408ad230fae57312"

# Test Plugin Config API when APISIX is working (should return HTTP 200)
curl http://localhost:9180/apisix/admin/plugin_configs \
  -H "X-API-KEY: a663d5f8d98fd490408ad230fae57312"

# Test Admin API when APISIX is hanging (will return HTTP 000)
curl http://localhost:9180/apisix/admin/services \
  -H "X-API-KEY: a663d5f8d98fd490408ad230fae57312"

Why Admin API Should Work

On your base system, the Admin API works because:

  1. APISIX is properly configured to connect to the correct etcd instance
  2. APISIX completes initialization without hanging
  3. Admin API becomes accessible on port 9180
  4. Plugin configurations sync correctly with etcd

In the reproduction environment, the Admin API doesn't work because:

  1. APISIX uses hardcoded config (127.0.0.1:2379) instead of custom config (etcd:2379)
  2. APISIX hangs during initialization trying to connect to localhost
  3. Admin API never becomes accessible because APISIX never completes startup
  4. Plugin configurations fail to sync due to the same etcd connection issue

πŸ“Š Monitoring and Debugging

The reproduction setup includes:

  • Health checks for etcd
  • Debug logging for APISIX
  • Connectivity tests between services
  • Process monitoring to detect hanging
  • Log analysis to identify hanging patterns

🚨 Cleanup

To clean up the reproduction environment:

# Easy way: Use the run script
sudo ./run_bug.sh clean

# Or manually
sudo docker-compose -f docker-compose.bug.yml down
sudo docker rmi apisix-etcd-hanging-bug_apisix-bug

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”— Related Issues

This bug reproduction is based on investigation documented in:

πŸ“ž Support

If you encounter any issues with this reproduction setup:

  1. Check the Issues page
  2. Create a new issue with detailed information
  3. Include logs and environment details

🎯 Complete Solution Summary

Issues Identified and Fixed:

  1. Primary Issue - Hardcoded etcd Configuration:

    • Problem: APISIX ignores custom config.yaml and uses hardcoded http://127.0.0.1:2379
    • Fix: Modified /usr/local/apisix/apisix/cli/config.lua during Docker build
    • Result: APISIX connects to etcd service instead of localhost
  2. Secondary Issue - Process Cleanup Failure:

    • Problem: Test scripts using kill $APISIX_PID left nginx processes running
    • Fix: Updated comprehensive test to use /usr/bin/apisix stop
    • Result: Proper cleanup between test iterations
  3. API Key Management:

    • Problem: Inconsistent API key handling across scripts
    • Fix: Centralized API key in .env file with environment variable substitution
    • Result: Consistent API key usage across all components
  4. Admin API Access:

    • Problem: Nginx configuration restricted Admin API access
    • Fix: Dynamic nginx configuration modification in test scripts
    • Result: Admin API accessible from host system

Final Status:

  • βœ… All tests pass consistently (3/3 iterations)
  • βœ… etcd sync and addon plugin functionality working
  • βœ… APISIX configuration stable and reliable
  • βœ… Process management working correctly
  • βœ… Comprehensive test suite validates all fixes
  • βœ… Two optimized scripts available (run_bug.sh and restart_bug.sh)
  • βœ… Common functions shared between scripts for maintainability

Key Takeaways:

  1. Root cause was hardcoded configuration in the APISIX Docker image overriding custom config files
  2. Addon syncing failure was NOT a separate issue - it was a cascading failure from the hardcoded etcd config
  3. Secondary issue was process cleanup in test scripts (discovered during comprehensive testing)
  4. Single hardcoded value broke ALL etcd-dependent functionality (Admin API, routes, plugins, etc.)
  5. All fixes work together to create a stable, reliable system
  6. Test suite validates that the solution is robust and consistent

🏷️ Tags

apisix etcd hanging bug reproduction docker api-gateway initialization sync route-management comprehensive-testing process-cleanup restart-script common-functions

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages