Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
8e37cdbf
Commit
8e37cdbf
authored
Mar 22, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure references is released after Job cancelling
parent
9b191f67
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
22 deletions
+32
-22
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
...mmonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
+4
-5
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+5
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
+23
-15
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
View file @
8e37cdbf
...
@@ -14,10 +14,8 @@ import io.ktor.client.request.*
...
@@ -14,10 +14,8 @@ import io.ktor.client.request.*
import
io.ktor.client.request.forms.MultiPartFormDataContent
import
io.ktor.client.request.forms.MultiPartFormDataContent
import
io.ktor.client.request.forms.formData
import
io.ktor.client.request.forms.formData
import
io.ktor.client.statement.HttpResponse
import
io.ktor.client.statement.HttpResponse
import
kotlinx.coroutines.CoroutineName
import
kotlinx.coroutines.*
import
kotlinx.coroutines.async
import
kotlinx.coroutines.io.ByteReadChannel
import
kotlinx.coroutines.io.ByteReadChannel
import
kotlinx.coroutines.withContext
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.json.JsonConfiguration
import
kotlinx.serialization.json.JsonConfiguration
...
@@ -342,14 +340,15 @@ internal abstract class QQAndroidBotBase constructor(
...
@@ -342,14 +340,15 @@ internal abstract class QQAndroidBotBase constructor(
return
json
.
parse
(
GroupAnnouncement
.
serializer
(),
rep
)
return
json
.
parse
(
GroupAnnouncement
.
serializer
(),
rep
)
}
}
@LowLevelAPI
@LowLevelAPI
@MiraiExperimentalAPI
@MiraiExperimentalAPI
override
suspend
fun
_lowLevelGetGroupActiveData
(
groupId
:
Long
):
GroupActiveData
{
override
suspend
fun
_lowLevelGetGroupActiveData
(
groupId
:
Long
):
GroupActiveData
{
val
data
=
network
.
async
{
val
data
=
network
.
async
{
HttpClient
().
get
<
String
>
{
HttpClient
().
get
<
String
>
{
url
(
"https://qqweb.qq.com/c/activedata/get_mygroup_data"
)
url
(
"https://qqweb.qq.com/c/activedata/get_mygroup_data"
)
parameter
(
"bkn"
,
bkn
)
parameter
(
"bkn"
,
bkn
)
parameter
(
"gc"
,
groupId
)
parameter
(
"gc"
,
groupId
)
headers
{
headers
{
append
(
append
(
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
8e37cdbf
...
@@ -180,6 +180,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -180,6 +180,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
// caches
// caches
private
val
_pendingEnabled
=
atomic
(
true
)
private
val
_pendingEnabled
=
atomic
(
true
)
internal
val
pendingEnabled
get
()
=
_pendingEnabled
.
value
internal
val
pendingEnabled
get
()
=
_pendingEnabled
.
value
@Volatile
@Volatile
internal
var
pendingIncomingPackets
:
LockFreeLinkedList
<
KnownPacketFactories
.
IncomingPacket
<
*
>>?
=
internal
var
pendingIncomingPackets
:
LockFreeLinkedList
<
KnownPacketFactories
.
IncomingPacket
<
*
>>?
=
LockFreeLinkedList
()
LockFreeLinkedList
()
...
@@ -189,8 +190,10 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -189,8 +190,10 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
check
(
bot
.
isActive
)
{
"bot is dead therefore network can't init"
}
check
(
bot
.
isActive
)
{
"bot is dead therefore network can't init"
}
check
(
this
@QQAndroidBotNetworkHandler
.
isActive
)
{
"network is dead therefore can't init"
}
check
(
this
@QQAndroidBotNetworkHandler
.
isActive
)
{
"network is dead therefore can't init"
}
bot
.
friends
.
delegate
.
clear
()
CancellationException
(
"re-init"
).
let
{
reInitCancellationException
->
bot
.
groups
.
delegate
.
clear
()
bot
.
friends
.
delegate
.
clear
{
it
.
cancel
(
reInitCancellationException
)
}
bot
.
groups
.
delegate
.
clear
{
it
.
cancel
(
reInitCancellationException
)
}
}
if
(!
pendingEnabled
)
{
if
(!
pendingEnabled
)
{
pendingIncomingPackets
=
LockFreeLinkedList
()
pendingIncomingPackets
=
LockFreeLinkedList
()
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
View file @
8e37cdbf
...
@@ -35,9 +35,14 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
...
@@ -35,9 +35,14 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
val
configuration
:
BotConfiguration
val
configuration
:
BotConfiguration
)
:
Bot
(),
CoroutineScope
{
)
:
Bot
(),
CoroutineScope
{
private
val
botJob
=
SupervisorJob
(
configuration
.
parentCoroutineContext
[
Job
])
private
val
botJob
=
SupervisorJob
(
configuration
.
parentCoroutineContext
[
Job
])
override
val
coroutineContext
:
CoroutineContext
=
final
override
val
coroutineContext
:
CoroutineContext
=
configuration
.
parentCoroutineContext
+
botJob
+
(
configuration
.
parentCoroutineContext
[
CoroutineExceptionHandler
]
configuration
.
parentCoroutineContext
+
botJob
+
(
configuration
.
parentCoroutineContext
[
CoroutineExceptionHandler
]
?:
CoroutineExceptionHandler
{
_
,
e
->
logger
.
error
(
"An exception was thrown under a coroutine of Bot"
,
e
)
})
?:
CoroutineExceptionHandler
{
_
,
e
->
logger
.
error
(
"An exception was thrown under a coroutine of Bot"
,
e
)
})
override
val
context
:
Context
by
context
.
unsafeWeakRef
()
override
val
context
:
Context
by
context
.
unsafeWeakRef
()
@OptIn
(
LowLevelAPI
::
class
)
@OptIn
(
LowLevelAPI
::
class
)
...
@@ -173,25 +178,28 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
...
@@ -173,25 +178,28 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
// endregion
// endregion
init
{
coroutineContext
[
Job
]
!!
.
invokeOnCompletion
{
throwable
->
network
.
close
(
throwable
)
offlineListener
.
cancel
(
CancellationException
(
"bot cancelled"
,
throwable
))
groups
.
delegate
.
clear
()
// job is cancelled, so child jobs are to be cancelled
friends
.
delegate
.
clear
()
instances
.
removeIf
{
it
.
get
()
?.
uin
==
this
.
uin
}
}
}
@OptIn
(
MiraiInternalAPI
::
class
)
@OptIn
(
MiraiInternalAPI
::
class
)
override
fun
close
(
cause
:
Throwable
?)
{
override
fun
close
(
cause
:
Throwable
?)
{
if
(!
this
.
botJob
.
isActive
)
{
if
(!
this
.
botJob
.
isActive
)
{
// already cancelled
// already cancelled
return
return
}
}
kotlin
.
runCatching
{
if
(
cause
==
null
)
{
if
(
cause
==
null
)
{
this
.
botJob
.
cancel
()
this
.
botJob
.
cancel
()
}
else
{
network
.
close
()
this
.
botJob
.
cancel
(
CancellationException
(
"bot cancelled"
,
cause
))
offlineListener
.
cancel
()
}
else
{
this
.
botJob
.
cancel
(
CancellationException
(
"bot cancelled"
,
cause
))
network
.
close
(
cause
)
offlineListener
.
cancel
(
CancellationException
(
"bot cancelled"
,
cause
))
}
}
}
groups
.
delegate
.
clear
()
friends
.
delegate
.
clear
()
instances
.
removeIf
{
it
.
get
()
?.
uin
==
this
.
uin
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment