NotImplemented error due to unsupported event loop method on Windows when starting server #604
Open
Description
Describe the issue
While trying to start codegate server on Windows, a NotImplemented
exception is raised and the server does not start.
Python version: 3.13.1
Steps to Reproduce
Set up the project as described here and run codegate serve
Operating System
Microsoft Windows (Intel)
IDE and Version
N/A
Extension and Version
N/A
Provider
Other
Model
N/A
Logs
{
"origin": "cli",
"event": "Unexpected error occurred during server execution",
"level": "error",
"timestamp": "2025-01-16T04:52:57.283694Z",
"module": "cli",
"pathname": "E:\\github_forks\\codegate-fork\\src\\codegate\\cli.py",
"exception": [
{
"exc_type": "NotImplementedError",
"exc_value": "",
"syntax_error": null,
"is_cause": false,
"frames": [
{
"filename": "E:\\github_forks\\codegate-fork\\src\\codegate\\cli.py",
"lineno": 391,
"name": "run_servers",
"locals": {
"cfg": "Config(\n port=8989,\n proxy_port=8990,\n host='localhost',\n log_level=<LogLevel.INFO: 'INFO'>,\n log_format=<LogFormat.JSON: 'JSON'>,\n prompts=PromptConfig(\n prompts={\n 'default_chat': 'You are CodeGate, a security-focused AI assistant.\\nYou specialize in software se'+1521,\n 'secrets_redacted': 'The files in the context contain sensitive information that has been redacted. D'+143,\n 'security_audit': 'You are a security expert conducting a thorough code review. Identify potential '+84,\n 'red_team': 'You are a red team member conducting a security assessment. Identify vulnerabili'+54,\n 'blue_team': 'You are a blue team member conducting a security assessment. Identify security c'+58\n }\n ),\n model_base_path='./codegate_volume/models',\n chat_model_n_ctx=32768,\n chat_model_n_gpu_layers=-1,\n embedding_model='all-minilm-L6-v2-q5_k_m.gguf',\n db_path=None,\n vec_db_path='./sqlite_data/vectordb.db',\n certs_dir='./codegate_volume/certs',\n ca_cert='ca.crt',\n ca_key='ca.key',\n server_cert='server.crt',\n server_key='server.key',\n force_certs=False,\n max_fim_hash_lifetime=300,\n provider_urls={\n 'openai': 'https://api.openai.com/v1',\n 'anthropic': 'https://api.anthropic.com/v1',\n 'vllm': 'http://localhost:8000',\n 'ollama': 'http://localhost:11434'\n }\n)",
"app": "<fastapi.applications.FastAPI object at 0x000002EE259556A0>",
"logger": "<BoundLoggerFilteringAtNotset(context={'origin': 'cli'}, processors=[<function add_log_level at 0x000002EE09FD9DA0>, <structlog.processors.TimeStamper object at 0x000002EE151C00C0>, <function add_origin at 0x000002EE09D62CA0>, <structlog.processors.CallsiteParameterAdder object at 0x000002EE243D5FC0>, <function ProcessorFormatter.wrap_for_formatter at 0x000002EE0C205DA0>])>",
"uvicorn_config": "<uvicorn.config.Config object at 0x000002EE259D0C20>",
"server": "<codegate.cli.UvicornServer object at 0x000002EE259D1010>",
"copilot_provider": "<codegate.providers.copilot.provider.CopilotProvider object at 0x000002EE259D1160>",
"tasks": "[\n <Task finished name='Task-2' coro=<UvicornServer.serve() done, defined at E:\\github_forks\\codegate-fork\\src\\codegate\\cli.py:38> exception=NotImplementedError()>,\n <Task pending name='Task-3' coro=<CopilotProvider.run_proxy_server() running at E:\\github_forks\\codegate-fork\\src\\codegate\\providers\\copilot\\provider.py:733> wait_for=<_GatheringFuture pending cb=[Task.task_wakeup()]> cb=[gather.<locals>._done_callback() at C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\asyncio\\tasks.py:820]>\n]",
"e": "NotImplementedError()"
}
},
{
"filename": "E:\\github_forks\\codegate-fork\\src\\codegate\\cli.py",
"lineno": 44,
"name": "serve",
"locals": {
"self": "<codegate.cli.UvicornServer object at 0x000002EE259D1010>",
"loop": "<ProactorEventLoop running=True closed=False debug=False>"
}
},
{
"filename": "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\asyncio\\events.py",
"lineno": 596,
"name": "add_signal_handler",
"locals": {
"self": "<ProactorEventLoop running=True closed=False debug=False>",
"sig": "<Signals.SIGTERM: 15>",
"callback": "<function UvicornServer.serve.<locals>.<lambda> at 0x000002EE25922480>",
"args": "()"
}
}
]
}
]
}
Additional Context
This is because add_signal_handler()
is not supported on Windows as highlighted here.
This issue dealt with this problem by writing add_signal_handler()
in try-except and I tried this as well just to see what happens. This does not raise NotImplemented
error but raises ValueError
because reuse_port
is not supported by socket module on Windows and it is used in class CopilotProvider's create_proxy_server()
.
{
"origin": "cli",
"event": "Unexpected error occurred during server execution",
"level": "error",
"timestamp": "2025-01-16T06:38:25.380003Z",
"module": "cli",
"pathname": "E:\\github_forks\\codegate-fork\\src\\codegate\\cli.py",
"exception": [
{
"exc_type": "ValueError",
"exc_value": "reuse_port not supported by socket module",
"syntax_error": null,
"is_cause": false,
"frames": [
{
"filename": "E:\\github_forks\\codegate-fork\\src\\codegate\\cli.py",
"lineno": 394,
"name": "run_servers",
"locals": {
"cfg": "Config(\n port=8989,\n proxy_port=8990,\n host='localhost',\n log_level=<LogLevel.INFO: 'INFO'>,\n log_format=<LogFormat.JSON: 'JSON'>,\n prompts=PromptConfig(\n prompts={\n 'default_chat': 'You are CodeGate, a security-focused AI assistant.\\nYou specialize in software se'+1521,\n 'secrets_redacted': 'The files in the context contain sensitive information that has been redacted. D'+143,\n 'security_audit': 'You are a security expert conducting a thorough code review. Identify potential '+84,\n 'red_team': 'You are a red team member conducting a security assessment. Identify vulnerabili'+54,\n 'blue_team': 'You are a blue team member conducting a security assessment. Identify security c'+58\n }\n ),\n model_base_path='./codegate_volume/models',\n chat_model_n_ctx=32768,\n chat_model_n_gpu_layers=-1,\n embedding_model='all-minilm-L6-v2-q5_k_m.gguf',\n db_path=None,\n vec_db_path='./sqlite_data/vectordb.db',\n certs_dir='./codegate_volume/certs',\n ca_cert='ca.crt',\n ca_key='ca.key',\n server_cert='server.crt',\n server_key='server.key',\n force_certs=False,\n max_fim_hash_lifetime=300,\n provider_urls={\n 'openai': 'https://api.openai.com/v1',\n 'anthropic': 'https://api.anthropic.com/v1',\n 'vllm': 'http://localhost:8000',\n 'ollama': 'http://localhost:11434'\n }\n)",
"app": "<fastapi.applications.FastAPI object at 0x0000023FD77CCD70>",
"logger": "<BoundLoggerFilteringAtNotset(context={'origin': 'cli'}, processors=[<function add_log_level at 0x0000023FBBED9DA0>, <structlog.processors.TimeStamper object at 0x0000023FD768CF40>, <function add_origin at 0x0000023FBBC62CA0>, <structlog.processors.CallsiteParameterAdder object at 0x0000023FC3416A80>, <function ProcessorFormatter.wrap_for_formatter at 0x0000023FBE0D5DA0>])>",
"uvicorn_config": "<uvicorn.config.Config object at 0x0000023FD7870830>",
"server": "<codegate.cli.UvicornServer object at 0x0000023FD7870C20>",
"copilot_provider": "<codegate.providers.copilot.provider.CopilotProvider object at 0x0000023FD7870D70>",
"tasks": "[\n <Task pending name='Task-2' coro=<UvicornServer.serve() running at E:\\github_forks\\codegate-fork\\src\\codegate\\cli.py:55> wait_for=<_GatheringFuture pending cb=[Task.task_wakeup()]> cb=[gather.<locals>._done_callback() at C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\asyncio\\tasks.py:820]>,\n <Task finished name='Task-3' coro=<CopilotProvider.run_proxy_server() done, defined at E:\\github_forks\\codegate-fork\\src\\codegate\\providers\\copilot\\provider.py:726> exception=ValueError('reuse_port not supported by socket module')>\n]",
"e": "ValueError('reuse_port not supported by socket module')"
}
},
{
"filename": "E:\\github_forks\\codegate-fork\\src\\codegate\\providers\\copilot\\provider.py",
"lineno": 733,
"name": "run_proxy_server",
"locals": {
"cls": "<class 'codegate.providers.copilot.provider.CopilotProvider'>",
"ca": "<codegate.ca.codegate_ca.CertificateAuthority object at 0x0000023FD77CD2B0>",
"ssl_context": "<ssl.SSLContext object at 0x0000023FD7827DA0>",
"config": "Config(\n port=8989,\n proxy_port=8990,\n host='localhost',\n log_level=<LogLevel.INFO: 'INFO'>,\n log_format=<LogFormat.JSON: 'JSON'>,\n prompts=PromptConfig(\n prompts={\n 'default_chat': 'You are CodeGate, a security-focused AI assistant.\\nYou specialize in software se'+1521,\n 'secrets_redacted': 'The files in the context contain sensitive information that has been redacted. D'+143,\n 'security_audit': 'You are a security expert conducting a thorough code review. Identify potential '+84,\n 'red_team': 'You are a red team member conducting a security assessment. Identify vulnerabili'+54,\n 'blue_team': 'You are a blue team member conducting a security assessment. Identify security c'+58\n }\n ),\n model_base_path='./codegate_volume/models',\n chat_model_n_ctx=32768,\n chat_model_n_gpu_layers=-1,\n embedding_model='all-minilm-L6-v2-q5_k_m.gguf',\n db_path=None,\n vec_db_path='./sqlite_data/vectordb.db',\n certs_dir='./codegate_volume/certs',\n ca_cert='ca.crt',\n ca_key='ca.key',\n server_cert='server.crt',\n server_key='server.key',\n force_certs=False,\n max_fim_hash_lifetime=300,\n provider_urls={\n 'openai': 'https://api.openai.com/v1',\n 'anthropic': 'https://api.anthropic.com/v1',\n 'vllm': 'http://localhost:8000',\n 'ollama': 'http://localhost:11434'\n }\n)"
}
},
{
"filename": "E:\\github_forks\\codegate-fork\\src\\codegate\\providers\\copilot\\provider.py",
"lineno": 720,
"name": "create_proxy_server",
"locals": {
"cls": "<class 'codegate.providers.copilot.provider.CopilotProvider'>",
"host": "'localhost'",
"port": "8990",
"ssl_context": "<ssl.SSLContext object at 0x0000023FD7827DA0>",
"loop": "<ProactorEventLoop running=True closed=False debug=False>"
}
},
{
"filename": "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\asyncio\\base_events.py",
"lineno": 1589,
"name": "create_server",
"locals": {
"self": "<ProactorEventLoop running=True closed=False debug=False>",
"protocol_factory": "<function CopilotProvider.create_proxy_server.<locals>.<lambda> at 0x0000023FD77123E0>",
"host": "'localhost'",
"port": "8990",
"family": "<AddressFamily.AF_UNSPEC: 0>",
"flags": "<AddressInfo.AI_PASSIVE: 1>",
"sock": "<socket.socket [closed] fd=-1, family=2, type=1, proto=0>",
"backlog": "100",
"ssl": "<ssl.SSLContext object at 0x0000023FD7827DA0>",
"reuse_address": "False",
"reuse_port": "True",
"keep_alive": "None",
"ssl_handshake_timeout": "None",
"ssl_shutdown_timeout": "None",
"start_serving": "False",
"sockets": "[<socket.socket [closed] fd=-1, family=2, type=1, proto=0>]",
"hosts": "['localhost']",
"fs": "[\n <coroutine object BaseEventLoop._create_server_getaddrinfo at 0x0000023FD77BE790>\n]",
"infos": "{\n (\n <AddressFamily.AF_INET: 2>,\n <SocketKind.SOCK_STREAM: 1>,\n 0,\n '',\n ('127.0.0.1', 8990)\n ),\n (\n <AddressFamily.AF_INET6: 23>,\n <SocketKind.SOCK_STREAM: 1>,\n 0,\n '',\n ('::1', 8990, 0, 0)\n )\n}",
"completed": "False",
"res": "(\n <AddressFamily.AF_INET: 2>,\n <SocketKind.SOCK_STREAM: 1>,\n 0,\n '',\n ('127.0.0.1', 8990)\n)",
"af": "<AddressFamily.AF_INET: 2>",
"socktype": "<SocketKind.SOCK_STREAM: 1>",
"proto": "0",
"canonname": "''",
"sa": "('127.0.0.1', 8990)"
}
},
{
"filename": "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\asyncio\\base_events.py",
"lineno": 91,
"name": "_set_reuseport",
"locals": {
"sock": "<socket.socket [closed] fd=-1, family=2, type=1, proto=0>"
}
}
]
}
]
}