diff --git a/aiosip/transaction.py b/aiosip/transaction.py
index da61942..4f2b0ab 100644
--- a/aiosip/transaction.py
+++ b/aiosip/transaction.py
@@ -145,6 +145,9 @@ class FutureTransaction(BaseTransaction):
         self.dialog.end_transaction(self)
 
     def _result(self, msg):
+        if self.authentification:
+            self.authentification.cancel()
+            self.authentification = None
         self._future.set_result(msg)
         self.dialog.end_transaction(self)
 

Improper handling of 401 authentication failures
In a call flow such as

* send REGISTER 
* get 401 response with auth challenge
* send REGISTER with valid authentication
* get 401 response with no challenge (ie: your credentials are fine, but still denied)

The client will continue to retransmit the request with the authorization header 
diff --git a/tests/test_sip_scenario.py b/tests/test_sip_scenario.py
index d38e7c3..fdb1a89 100644
--- a/tests/test_sip_scenario.py
+++ b/tests/test_sip_scenario.py
@@ -92,6 +92,53 @@ async def test_authentication(test_server, protocol, loop, from_details, to_deta
     await app.close()
 
 
+async def test_authentication_rejection(test_server, protocol, loop, from_details, to_details):
+    received_messages = list()
+
+    class Dialplan(aiosip.BaseDialplan):
+
+        async def resolve(self, *args, **kwargs):
+            await super().resolve(*args, **kwargs)
+            return self.subscribe
+
+        async def subscribe(self, request, message):
+            dialog = request._create_dialog()
+
+            received_messages.append(message)
+            await dialog.unauthorized(message)
+
+            async for message in dialog:
+                received_messages.append(message)
+                await dialog.reply(message, 401)
+
+    app = aiosip.Application(loop=loop)
+    server_app = aiosip.Application(loop=loop, dialplan=Dialplan())
+    server = await test_server(server_app)
+
+    peer = await app.connect(
+        protocol=protocol,
+        remote_addr=(
+            server.sip_config['server_host'],
+            server.sip_config['server_port'],
+        )
+    )
+
+    result = await peer.register(
+        expires=1800,
+        from_details=aiosip.Contact.from_header(from_details),
+        to_details=aiosip.Contact.from_header(to_details),
+        password='testing_pass',
+    )
+
+    # wait long enough to ensure no improper retransmit
+    await asyncio.sleep(1)
+    assert len(received_messages) == 2
+    assert result.status_code == 401
+
+    await server_app.close()
+    await app.close()
+
+
 async def test_invite(test_server, protocol, loop, from_details, to_details):
     call_established = loop.create_future()
     call_disconnected = loop.create_future()

pip install -e .[dev]
parse_log_pytest
Pipfile
pytest pytest-cov pytest-asyncio
apt-get update apt-get install -y gcc
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
aiodns==3.2.0
-e git+https://github.com/Eyepea/aiosip.git@3219ca46cdfd115a72101d92cd1f717f78d9f7b9#egg=aiosip
attrs==22.2.0
certifi==2021.5.30
cffi==1.15.1
coverage==6.2
cssselect==1.1.0
importlib-metadata==4.8.3
iniconfig==1.1.1
lxml==5.3.1
multidict==5.2.0
packaging==21.3
pipfile==0.0.2
pluggy==1.0.0
py==1.11.0
pycares==4.3.0
pycparser==2.21
pyparsing==3.1.4
pyquery==1.4.3
pytest==7.0.1
pytest-asyncio==0.16.0
pytest-cov==4.0.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
tomli==1.2.3
typing_extensions==4.1.1
websockets==9.1
zipp==3.6.0

name: aiosip
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - pipfile=0.0.2=py_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - aiodns==3.2.0
      - attrs==22.2.0
      - cffi==1.15.1
      - coverage==6.2
      - cssselect==1.1.0
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - lxml==5.3.1
      - multidict==5.2.0
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pycares==4.3.0
      - pycparser==2.21
      - pyparsing==3.1.4
      - pyquery==1.4.3
      - pytest==7.0.1
      - pytest-asyncio==0.16.0
      - pytest-cov==4.0.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - websockets==9.1
      - zipp==3.6.0
prefix: /opt/conda/envs/aiosip

tests/test_sip_scenario.py::test_authentication_rejection[udp] tests/test_sip_scenario.py::test_authentication_rejection[tcp] tests/test_sip_scenario.py::test_invite[udp] tests/test_sip_scenario.py::test_cancel[udp]
tests/test_sip_scenario.py::test_notify[udp] tests/test_sip_scenario.py::test_notify[tcp] tests/test_sip_scenario.py::test_authentication[udp] tests/test_sip_scenario.py::test_authentication[tcp] tests/test_sip_scenario.py::test_invite[tcp] tests/test_sip_scenario.py::test_cancel[tcp]
aiosip/transaction.py
aiosip/transaction.py