Skip to content

Commit 7779110

Browse files
Eddie Renfacebook-github-bot
authored andcommitted
Make MCP/Thrift ContextProp compatible with lifetime pairing
Summary: For lifetime pairing requests, Thrift Framework Metadata is currently missing on the WWW side. This diff is a proof-of-concept fix. But ideally we shouldn't be recreating the thrift metadata. I'm fairly confident it is indeed being created from timestamp logs, but it ends up as null when lifetime pairing thrift client is called. Context(Prop) workplace post: https://fb.workplace.com/groups/515642096314492/posts/1381729806372379 Differential Revision: D73286706 fbshipit-source-id: 7b407bf6ce22901d8453e1066b21c85bac2f6e74
1 parent ea2855e commit 7779110

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

third-party/thrift/src/thrift/lib/hack/src/ThriftContextPropState.php

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ public static function initFromHeaders()[defaults]: void {
4444
self::initFromString($tfm, $skip_experiment_id_ingestion);
4545
}
4646

47+
/**
48+
* Initializes ThriftContextPropState from WWW subrequest Headers.
49+
* Takes in custom subrequest headers
50+
*/
51+
public static function getOriginIdFromSubrequestHeaders(
52+
HTTPHeaders $headers,
53+
)[defaults]: ?int {
54+
$tfm = $headers->getHeader(HTTPRequestHeader::THRIFT_FMHK);
55+
$skip_experiment_id_ingestion =
56+
!JustKnobs::eval('lumos/experimentation:enable_www_experiment_id_api');
57+
if ($tfm === null) {
58+
return 0;
59+
}
60+
return
61+
self::getTfmFromString($tfm, $skip_experiment_id_ingestion)->origin_id;
62+
}
63+
4764
// If anything changes with the ThriftFrameworkMetadata, throw out the
4865
// serialized representation.
4966
private function dirty()[write_props]: void {
@@ -100,24 +117,16 @@ public static function initFromString(
100117
)[defaults]: void {
101118
try {
102119
$rid_set = false;
120+
103121
if ($s !== null) {
104-
$transport = Base64::decode($s);
105-
$buf = new TMemoryBuffer($transport);
106-
$prot = new TCompactProtocolAccelerated($buf);
107-
$tfm = ThriftFrameworkMetadata::withDefaultValues();
108-
$tfm->read($prot);
122+
$tfm = self::getTfmFromString($s, $skip_experiment_id_ingestion);
123+
self::get()->storage = $tfm;
124+
self::get()->dirty();
109125

110126
$rid = $tfm->request_id;
111127
if ($rid !== null && !Str\is_empty($rid)) {
112128
$rid_set = true;
113129
}
114-
115-
if ($skip_experiment_id_ingestion && $tfm->experiment_ids is nonnull) {
116-
$tfm->experiment_ids = vec[];
117-
}
118-
119-
self::get()->storage = $tfm;
120-
self::get()->dirty();
121130
}
122131
} catch (\Exception $ex) {
123132
// Swallow the error, rather than nuke the whole request
@@ -132,6 +141,24 @@ public static function initFromString(
132141
}
133142
}
134143

144+
private static function getTfmFromString(
145+
string $s,
146+
bool $skip_experiment_id_ingestion = true,
147+
): ThriftFrameworkMetadata {
148+
$transport = Base64::decode($s);
149+
$buf = new TMemoryBuffer($transport);
150+
$prot = new TCompactProtocolAccelerated($buf);
151+
$tfm = ThriftFrameworkMetadata::withDefaultValues();
152+
$tfm->read($prot);
153+
154+
if ($skip_experiment_id_ingestion && $tfm->experiment_ids is nonnull) {
155+
$tfm->experiment_ids = vec[];
156+
}
157+
158+
return $tfm;
159+
160+
}
161+
135162
// update FB user id from explicit value
136163
public static function updateFBUserId(?int $fb_user_id, string $src): bool {
137164
// don't overwrite if TCPS already has a valid fb user id

0 commit comments

Comments
 (0)